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
Copy file name to clipboardExpand all lines: src/content/docs/identityserver/fundamentals/resources/isolation.md
+36-12Lines changed: 36 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,9 @@ redirect_from:
14
14
This is an Enterprise Edition feature.
15
15
:::
16
16
17
-
OAuth itself only knows about scopes - the (API) resource concept does not exist from a pure protocol point of view. This means that all the requested scope and audience combination get merged into a single access token. This has a couple of downsides, e.g.
17
+
OAuth itself only knows about scopes - the (API) resource concept does not exist from a pure protocol point of view.
18
+
This means that all the requested scope and audience combination get merged into a single access token.
19
+
This has a couple of downsides:
18
20
19
21
* tokens can become very powerful (and big)
20
22
* if such a token leaks, it allows access to multiple resources
@@ -23,13 +25,15 @@ OAuth itself only knows about scopes - the (API) resource concept does not exist
23
25
* resource specific processing like signing or encryption algorithms conflict
24
26
* without sender-constraints, a resource could potentially re-use (or abuse) a token to call another contained resource directly
25
27
26
-
To solve this problem [RFC 8707](https://tools.ietf.org/html/rfc8707) adds another request parameter for the authorize and token endpoint called `resource`. This allows requesting a token for a specific resource (in other words - making sure the audience claim has a single value only, and all scopes belong to that single resource).
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
30
+
value only, and all scopes belong to that single resource).
27
31
28
32
## Using The Resource Parameter
29
33
30
34
Let's assume you have the following resource design and that the client is allowed access to all scopes:
31
35
32
-
```cs
36
+
```csharp title="ApiResources.cs"
33
37
varresources=new[]
34
38
{
35
39
newApiResource("urn:invoices")
@@ -44,10 +48,12 @@ var resources = new[]
44
48
};
45
49
```
46
50
47
-
If the client would request a token for the `read` scope, the resulting access token would contain the audience of both the invoice and the products API and thus be accepted at both APIs.
51
+
If the client would request a token for the `read` scope, the resulting access token would contain the audience of both
52
+
the invoice and the products API and thus be accepted at both APIs.
48
53
49
54
### Machine to Machine Scenarios
50
-
If the client in addition passes the `resource` parameter specifying the name of the resource where it wants to use the access token, the token engine can `down-scope` the resulting access token to the single resource, e.g.:
55
+
If the client in addition passes the `resource` parameter specifying the name of the resource where it wants to use
56
+
the access token, the token engine can `down-scope` the resulting access token to the single resource, e.g.:
51
57
52
58
```text
53
59
POST /token
@@ -112,7 +118,8 @@ redirect_uri=...&
112
118
resource=urn:invoices
113
119
```
114
120
115
-
Which will return an access token for the invoices API and a refresh token. If you want to also retrieve the access token for the products API, you use the refresh token and make another roundtrip to the token endpoint.
121
+
This will return an access token for the invoices API and a refresh token. If you want to also retrieve the access token
122
+
for the products API, you use the refresh token and make another roundtrip to the token endpoint.
116
123
117
124
```text
118
125
POST /token
@@ -125,24 +132,41 @@ refresh_token=...&
125
132
resource=urn:products
126
133
```
127
134
128
-
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.
135
+
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.
129
136
130
137
## Enforcing Resource Isolation
131
-
All examples so far used the `resource` parameter optionally. If you have API resources, where you want to make sure they are not sharing access tokens with other resources, you can enforce the resource indicator, e.g.:
138
+
All examples so far used the `resource` parameter optionally. If you have API resources, where you want to make sure
139
+
they are not sharing access tokens with other resources, you can enforce the resource indicator, e.g.:
132
140
133
-
```cs
141
+
```csharp title="ApiResources.cs" {6,12}
134
142
varresources=new[]
135
143
{
136
144
newApiResource("urn:invoices")
137
145
{
138
146
Scopes= { "read", "write" },
139
-
140
147
RequireResourceIndicator=true
141
148
},
142
149
143
150
newApiResource("urn:products")
144
151
{
145
-
Scopes= { "read", "write" }
152
+
Scopes= { "read", "write" },
153
+
RequireResourceIndicator=true
146
154
}
147
155
};
148
-
```
156
+
```
157
+
158
+
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
161
+
the scopes.
162
+
163
+
Instead, `RequireResourceIndicator` controls **when** the resource's URI is included in the **audience claim** (`aud`)
164
+
of the issued access token.
165
+
166
+
* When `RequireResourceIndicator` is `false` (the default):
167
+
IdentityServer **automatically includes** the API's resource URI in the token's audience if any of the resource's scopes
168
+
are requested, even if the `resource` parameter was not sent in the request or didn't contain the resource URI.
169
+
* 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**
171
+
via the `resource` parameter when requesting the token.
0 commit comments