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
This violates the Principle of Least Privilege. If this token is leaked from the Inventory API, it can be used to call the Invoice API.
27
42
28
-
To solve this problem [RFC 8707](https://tools.ietf.org/html/rfc8707) adds another request parameter for the authorize and token endpoint called `resource`.
29
-
This allows requesting a token for a specific resource (in other words - making sure the audience claim has a single
43
+
To solve this problem [RFC 8707](https://tools.ietf.org/html/rfc8707) adds another request parameter for the authorize and token endpoint called `resource`.
44
+
This allows requesting a token for a specific resource (in other words - making sure the audience claim has a single
30
45
value only, and all scopes belong to that single resource).
31
46
32
47
## Using The Resource Parameter
@@ -52,7 +67,8 @@ If the client would request a token for the `read` scope, the resulting access t
52
67
the invoice and the products API and thus be accepted at both APIs.
53
68
54
69
### Machine to Machine Scenarios
55
-
If the client in addition passes the `resource` parameter specifying the name of the resource where it wants to use
70
+
71
+
If the client in addition passes the `resource` parameter specifying the name of the resource where it wants to use
56
72
the access token, the token engine can `down-scope` the resulting access token to the single resource, e.g.:
57
73
58
74
```text
@@ -70,13 +86,14 @@ Thus resulting in an access token like this (some details omitted):
70
86
71
87
```json
72
88
{
73
-
"aud": ["urn:invoice"],
74
-
"scope": "read",
75
-
"client_id": "client"
89
+
"aud": ["urn:invoice"],
90
+
"scope": "read",
91
+
"client_id": "client"
76
92
}
77
93
```
78
94
79
95
### Interactive Applications
96
+
80
97
The authorize endpoint supports the `resource` parameter as well, e.g.:
81
98
82
99
```text
@@ -98,6 +115,7 @@ resource=urn:invoices
98
115
```
99
116
100
117
### Requesting Access To Multiple Resources
118
+
101
119
It is also possible to request access to multiple resources. This will result in multiple access tokens - one for each request resource.
102
120
103
121
```text
@@ -135,7 +153,8 @@ resource=urn:products
135
153
The end-result will be that the client has two access tokens - one for each resource and can manage their lifetime via the refresh token.
136
154
137
155
## Enforcing Resource Isolation
138
-
All examples so far used the `resource` parameter optionally. If you have API resources, where you want to make sure
156
+
157
+
All examples so far used the `resource` parameter optionally. If you have API resources, where you want to make sure
139
158
they are not sharing access tokens with other resources, you can enforce the resource indicator, e.g.:
140
159
141
160
```csharp title="ApiResources.cs" {6,12}
@@ -156,17 +175,79 @@ var resources = new[]
156
175
```
157
176
158
177
The `RequireResourceIndicator` property **does not** mean that clients are forced to send the `resource` parameter when
159
-
they request scopes associated with the API resource. You can still request those scopes without setting the `resource`
160
-
parameter (or including the resource), and IdentityServer will issue a token as long as the client is allowed to request
178
+
they request scopes associated with the API resource. You can still request those scopes without setting the `resource`
179
+
parameter (or including the resource), and IdentityServer will issue a token as long as the client is allowed to request
161
180
the scopes.
162
181
163
-
Instead, `RequireResourceIndicator` controls **when** the resource's URI is included in the **audience claim** (`aud`)
182
+
Instead, `RequireResourceIndicator` controls **when** the resource's URI is included in the **audience claim** (`aud`)
164
183
of the issued access token.
165
184
166
185
* When `RequireResourceIndicator` is `false` (the default):
167
186
IdentityServer **automatically includes** the API's resource URI in the token's audience if any of the resource's scopes
168
187
are requested, even if the `resource` parameter was not sent in the request or didn't contain the resource URI.
169
188
* When `RequireResourceIndicator` is `true`:
170
-
The API's resource URI will **only** be included in the audience **if the client explicitly includes the resource URI**
189
+
The API's resource URI will **only** be included in the audience **if the client explicitly includes the resource URI**
171
190
via the `resource` parameter when requesting the token.
172
191
192
+
## .NET Client Implementation
193
+
194
+
While the examples above show the underlying HTTP protocol, .NET clients can use the Duende libraries to handle resource indicators easily.
195
+
196
+
### Machine-to-Machine (Worker)
197
+
198
+
When using `Duende.IdentityModel` for client credentials, you can pass the `resource` parameter using the `Parameters` dictionary:
0 commit comments