Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/274188a/blazor-auth0-dotnet9
Experiments with Auth0
https://github.com/274188a/blazor-auth0-dotnet9
aspire auth0 auth0-jwt blazor dotnet9 monolith-architecture
Last synced: 10 days ago
JSON representation
Experiments with Auth0
- Host: GitHub
- URL: https://github.com/274188a/blazor-auth0-dotnet9
- Owner: 274188A
- License: mit
- Created: 2025-01-02T05:18:27.000Z (11 days ago)
- Default Branch: main
- Last Pushed: 2025-01-03T09:38:00.000Z (10 days ago)
- Last Synced: 2025-01-03T10:25:55.709Z (10 days ago)
- Topics: aspire, auth0, auth0-jwt, blazor, dotnet9, monolith-architecture
- Language: C#
- Homepage:
- Size: 753 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Blazor App with Aspire and Auth0 Integration
This is a **very simple Blazor app** that integrates **Aspire** and **Auth0** for identity management. The app uses Auth0 to define roles, which are added to the identity token using a **post-login event trigger**.
## Key Features
- **Roles Defined in Auth0**: Roles are set up in Auth0 and injected into the identity token via a post-login trigger.
- **Mapping Auth0 Roles**: The C# code translates Auth0 role claims into standard roles for use within the application.### Example of Role Claim Mapping Using Trigger Post-Login
```javascript
exports.onExecutePostLogin = async (event, api) => {
const roleClaim = 'https://blazorserverapp.local';
if (event.authorization) {
api.idToken.setCustomClaim(${roleClaim}/roles, event.authorization.roles);
}
};
```### Code To Map Auth0 Roles to Standard Roles
The application contains C# logic to map the Auth0 roles:
```csharp
// Add claim mapping logic to include custom roles
builder.Services.Configure(Auth0Constants.AuthenticationScheme, options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
RoleClaimType = $"{audience}/roles" // Map custom role claim
};options.Events = new OpenIdConnectEvents
{
OnTokenValidated = context =>
{
if (context.Principal?.Identity is ClaimsIdentity identity)
{
// Map custom roles to standard role claims
var roleClaims = identity.FindAll($"{audience}/roles").ToList();
foreach (var roleClaim in roleClaims)
{
identity.AddClaim(new Claim(ClaimTypes.Role, roleClaim.Value));
}
}return Task.CompletedTask;
}
};
});
```