Skip to content

Commit 682bb2d

Browse files
committed
feat!: change token management for users to be outside the scope of the lib.
BREAKING CHANGE: Use Services.AddHttpClient("AuthClient", (sp, httpClient) => ...).AddUserAccessTokenHandler(); or any other kinds of token management, and then use "AuthClient" to inform lib which client it should use. CgScriptOptions.Site is no longer used. Set the BaseAddress of the httpClient in the above config to decide which site to call.
1 parent 5420032 commit 682bb2d

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

README.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ Add the following to the appsettings.json with the scopes you made above and you
5353
"SaveTokens": true
5454
},
5555
"CatglobeApi": {
56-
"FolderResourceId": deploymentFolderId,
57-
"Site": "https://mysite.catglobe.com/"
56+
"FolderResourceId": deploymentFolderId
5857
}
5958
```
6059

@@ -105,18 +104,20 @@ services.AddAuthentication(SCHEMENAME)
105104
oidcOptions.TokenValidationParameters.NameClaimType = "name";
106105
})
107106
.AddCookie(CookieAuthenticationDefaults.AuthenticationScheme);
108-
services.AddCgScript(builder.Configuration.GetSection("CatglobeApi"), builder.Environment.IsDevelopment());
107+
services.AddHttpClient("AuthClient", (sp, httpClient) => {
108+
var site = sp.GetService<IOptionsMonitor<OpenIdConnectOptions>>()?.Get(SCHEMENAME).Authority;
109+
httpClient.BaseAddress = string.IsNullOrEmpty(site) ? null : new(site);
110+
httpClient.DefaultRequestHeaders.Accept.Clear();
111+
httpClient.DefaultRequestHeaders.Accept.Add(new("application/json"));
112+
})
113+
.AddUserAccessTokenHandler(); //<-- here we use Duande for token management
114+
services
115+
.AddBlazorServerAccessTokenManagement<HybridCacheTokenStore>()
116+
.AddOpenIdConnectAccessTokenManagement();
117+
118+
services.AddCgScript(builder.Configuration.GetSection("CatglobeApi"), builder.Environment.IsDevelopment(), "AuthClient");
109119
```
110120

111-
Optionally, setup refresh-token refreshing as part of the cookie handling:
112-
```csharp
113-
services.AddSingleton<CookieOidcRefresher>();
114-
services.AddOptions<CookieAuthenticationOptions>(CookieAuthenticationDefaults.AuthenticationScheme).Configure<CookieOidcRefresher>((cookieOptions, refresher) => {
115-
cookieOptions.Events.OnValidatePrincipal = context => refresher.ValidateOrRefreshCookieAsync(context, SCHEMENAME);
116-
});
117-
```
118-
You can find the CookieOidcRefresher [here](https://github.com/dotnet/blazor-samples/blob/main/9.0/BlazorWebAppOidc/BlazorWebAppOidc/CookieOidcRefresher.cs).
119-
120121
Before `app.Run`, add the following:
121122
```csharp
122123
{

0 commit comments

Comments
 (0)