Skip to content

Commit f2d8d70

Browse files
authored
Duende Access Token Management (#35961)
1 parent 5bffbaf commit f2d8d70

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

aspnetcore/blazor/security/blazor-web-app-with-oidc.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,30 @@ At this point, Razor components can adopt [role-based and policy-based authoriza
14651465
* Security groups appear in `groups` claims, one claim per group. The security group GUIDs appear in the Azure portal when you create a security group and are listed when selecting **Identity** > **Overview** > **Groups** > **View**.
14661466
* Built-in ME-ID administrator roles appear in `wids` claims, one claim per role. The `wids` claim with a value of `b79fbf4d-3ef9-4689-8143-76b194e85509` is always sent by ME-ID for non-guest accounts of the tenant and doesn't refer to an administrator role. Administrator role GUIDs (*role template IDs*) appear in the Azure portal when selecting **Roles & admins**, followed by the ellipsis (**…**) > **Description** for the listed role. The role template IDs are also listed in [Microsoft Entra built-in roles (Entra documentation)](/entra/identity/role-based-access-control/permissions-reference).
14671467

1468+
## Alternative: Duende Access Token Management
1469+
1470+
In the sample app, a custom cookie refresher (`CookieOidcRefresher.cs`) implementation is used to perform automatic non-interactive token refresh. An alternative solution can be found in the open source [`Duende.AccessTokenManagement.OpenIdConnect` package](https://docs.duendesoftware.com/accesstokenmanagement/web-apps/).
1471+
1472+
Duende Access Token Management provides automatic access token management features for .NET worker and ASP.NET Core web apps, including Blazor, without the need to add a custom cookie refresher.
1473+
1474+
After the package is installed, remove the `CookieOidcRefresher` and add access token management for the currently logged-in user in the `Program` file:
1475+
1476+
```csharp
1477+
// Add services for token management
1478+
builder.Services.AddOpenIdConnectAccessTokenManagement();
1479+
1480+
// Register a typed HTTP client with token management support
1481+
builder.Services.AddHttpClient<InvoiceClient>(client =>
1482+
{
1483+
client.BaseAddress = new Uri("https://api.example.com/invoices/");
1484+
})
1485+
.AddUserAccessTokenHandler();
1486+
```
1487+
1488+
The [typed HTTP client](xref:blazor/call-web-api#typed-httpclient) (or [named HTTP client](xref:blazor/call-web-api#named-httpclient-with-ihttpclientfactory), if implemented) has automatic access token lifetime management on behalf of the currently logged-in user, including transparent refresh token management.
1489+
1490+
For more information, see the [Duende Access Token Management documentation for Blazor](https://docs.duendesoftware.com/accesstokenmanagement/blazor-server/).
1491+
14681492
## Troubleshoot
14691493

14701494
[!INCLUDE[](~/blazor/security/includes/troubleshoot-server.md)]

0 commit comments

Comments
 (0)