Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/JeepNL/Blazor-WASM-Identity-gRPC
Blazor WASM, IdentityServer4 with Multiple Roles, Additional User Claim(s) & gRPC Roles Authorization
https://github.com/JeepNL/Blazor-WASM-Identity-gRPC
blazor claims efcore grpc grpc-web identityserver4 kestrel roles sqlite wasm webassembly
Last synced: 2 months ago
JSON representation
Blazor WASM, IdentityServer4 with Multiple Roles, Additional User Claim(s) & gRPC Roles Authorization
- Host: GitHub
- URL: https://github.com/JeepNL/Blazor-WASM-Identity-gRPC
- Owner: JeepNL
- License: mit
- Created: 2020-06-21T09:55:47.000Z (over 4 years ago)
- Default Branch: Main
- Last Pushed: 2023-07-06T09:10:05.000Z (over 1 year ago)
- Last Synced: 2024-08-01T02:26:53.627Z (5 months ago)
- Topics: blazor, claims, efcore, grpc, grpc-web, identityserver4, kestrel, roles, sqlite, wasm, webassembly
- Language: C#
- Homepage:
- Size: 341 KB
- Stars: 100
- Watchers: 7
- Forks: 16
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Blazor WASM, IdentityServer4 with Multiple Roles, Additional User Claim(s) & gRPC Roles Authorization
![Blazor Template Screenshot](img/screenshot.jpg)
![.NET Core](https://github.com/JeepNL/Blazor-WASM-Identity-gRPC/workflows/.NET%20Core/badge.svg) _(Whoa Nelly, this thing does work!)_ 😉
### This .NET 6 Preview repo combines two repo's by **@javiercn**:
1. https://github.com/javiercn/BlazorAuthRoles
2. https://github.com/javiercn/BlazorGrpcAuth(_To run this repo you'll need **.NET 6.0 [SDK](https://dotnet.microsoft.com/download/dotnet-core)** and **Visual Studio [Preview](https://docs.microsoft.com/en-us/visualstudio/releases/2019/release-notes-preview)**_)
I've added Role Authorization to the -[Greeter](BlazorTemplate/Client/Pages/GreeterGrpc.razor) -[gRPC](BlazorTemplate/Shared/Contracts/greeter.proto) -[Service](BlazorTemplate/Server/GrpcServices/GreeterService.cs):
_Server/[Startup.cs](BlazorTemplate/Server/Startup.cs)_
endpoints
.MapGrpcService()
.RequireAuthorization(new AuthorizeAttribute { Roles = "Administrator"})
.EnableGrpcWeb();
I've also added a _Client/[Claims.razor](BlazorTemplate/Client/Pages/Claims.razor)_ page with a list of the current user's claims.It uses Kestrel as the default webserver, a SQLite database and is "*CTRL-F5'able*" without any further configuration.
You can delete de SQLite database and migrations folder if you want and use the following commands in Visual Studio's Package Manager Console to re-create the db.
1. Add-Migration InitialCreate
2. Update-DatabaseAt first run the app will create 2 users (_if they don't exist, see: Server/[SeedData.cs](BlazorTemplate/Server/Data/SeedData.cs)_)
1. `[email protected]` / `Qwerty1234#`
2. `[email protected]` / `Qwerty1234#`and 2 roles:
1. Users
2. AdministratorsThe 'Administrators' & 'Users' roles will be assigned to: `[email protected]`
The 'Users' role will be assigned to: `[email protected]`
### Additional Claim(s)
(_By George, I think I've got it_)1. I've extended ASP.NET Identity AspNetUsers table with an extra 'CustomClaim' field (_see: Server/Models/[ApplicationUser.cs](BlazorTemplate/Server/Models/ApplicationUser.cs)_).
2. Seeded a value to that `CustomClaim` field in: _Server/Data/[SeedData.cs](BlazorTemplate/Server/Data/SeedData.cs)_
3. Added: _Server/[AppClaimsPrincipalFactory.cs](BlazorTemplate/Server/AppClaimsPrincipalFactory.cs)_
4. Modified: _Server/[Startup.cs](BlazorTemplate/Server/Startup.cs)_ to use `AppClaimsPrincipalFactory.cs`
5. When you run the app you'll see the `custom_claim` in the _Client/Pages/[Claims.razor](BlazorTemplate/Client/Pages/Claims.razor)_ page