You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The example above is simplified to demonstrate the way that you might obtain a token. Embedded endpoints will typically enforce constraints on the way the API is called, aggregate multiple calls, or perform other business logic. Embedded endpoints that merely forward requests from the frontend to the remote API may not be needed at all. Instead, you could proxy the requests through the BFF using either the [simple http forwarder](/bff/fundamentals/apis/remote.mdx) or [YARP](/bff/fundamentals/apis/yarp.md).
Copy file name to clipboardExpand all lines: src/content/docs/bff/fundamentals/tokens.md
+21-31Lines changed: 21 additions & 31 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -15,20 +15,20 @@ Duende.BFF includes an automatic token management feature. This uses the access
15
15
16
16
For most scenarios, there is no additional configuration necessary. The token management will infer the configuration and token endpoint URL from the metadata of the OpenID Connect provider.
17
17
18
-
The easiest way to retrieve the current access token is to use an extension method on *HttpContext*:
18
+
The easiest way to retrieve the current access token is to use an extension method on `HttpContext`:
You can then use the token to set it on an *HttpClient*instance:
24
+
You can then use the token to set it on an `HttpClient`instance:
25
25
26
26
```csharp
27
27
varclient=newHttpClient();
28
28
client.SetBearerToken(token);
29
29
```
30
30
31
-
We recommend to leverage the *HttpClientFactory* to fabricate HTTP clients that are already aware of the token management plumbing. For this you would register a named client in your application startup e.g. like this:
31
+
We recommend to use the `HttpClientFactory` to create HTTP clients that are already aware of the token management plumbing. For this you would register a named client in your application startup e.g. like this:
The client will internally always try to use a current and valid access token. If for any reason this is not possible, the 401 status code will be returned to the caller.
78
+
The client will internally always try to use a current and valid access token. If for any reason this is not possible, the 401 status code will be returned to the caller.
91
79
92
80
### Reuse of Refresh Tokens
93
-
We recommend that you configure IdentityServer to issue reusable refresh tokens to BFF clients. Because the BFF is a confidential client, it does not need one-time use refresh tokens. Reusable refresh tokens are desirable because they avoid performance and user experience problems associated with one time use tokens. See the discussion on [rotating refresh tokens](/identityserver/tokens/refresh.md) and the [OAuth 2.0 Security Best Current Practice](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#section-2.2.2) for more details.
81
+
82
+
We recommend that you configure IdentityServer to issue reusable refresh tokens to BFF clients. Because the BFF is a confidential client, it does not need one-time use refresh tokens. Reusable refresh tokens are desirable because they avoid performance and user experience problems associated with one time use tokens. See the discussion on [rotating refresh tokens](/identityserver/tokens/refresh.md) and the [OAuth 2.0 Security Best Current Practice](https://datatracker.ietf.org/doc/html/draft-ietf-oauth-security-topics#section-2.2.2) for more details.
94
83
95
84
### Manually revoking refresh tokens
96
-
Duende.BFF revokes refresh tokens automatically at logout time. This behavior can be disabled with the *RevokeRefreshTokenOnLogout* option.
85
+
86
+
Duende.BFF revokes refresh tokens automatically at logout time. This behavior can be disabled with the _RevokeRefreshTokenOnLogout_ option.
97
87
98
88
If you want to manually revoke the current refresh token, you can use the following code:
Under the covers, the `AddLocalApiAuthentication` helper does a couple of things:
101
+
102
+
Under the hood, the `AddLocalApiAuthentication` helper does a couple of things:
92
103
93
104
* adds an authentication handler that validates incoming tokens using IdentityServer's built-in token validation engine (the name of this handler is `IdentityServerAccessToken` or `IdentityServerConstants.LocalApi.AuthenticationScheme`
94
105
* configures the authentication handler to require a scope claim inside the access token of value `IdentityServerApi`
95
106
* sets up an authorization policy that checks for a scope claim of value `IdentityServerApi`
96
107
97
108
This covers the most common scenarios. You can customize this behavior in the following ways:
98
109
99
-
* Add the authentication handler yourself by calling `services.AddAuthentication().AddLocalApi(...)`
100
-
* this way you can specify the required scope name yourself, or (by specifying no scope at all) accept any token from the current IdentityServer instance
110
+
* Add the authentication handler yourself by calling `services.AddAuthentication().AddLocalApi(...)`.
111
+
This way you can specify the required scope name yourself, or (by specifying no scope at all) accept any token from the current IdentityServer instance
101
112
* Do your own scope validation/authorization in your controllers using custom policies or code, e.g.:
0 commit comments