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
{{ message }}
This repository was archived by the owner on May 3, 2024. It is now read-only.
Copy file name to clipboardExpand all lines: 6-AdvancedScenarios/3-call-api-acrs/README.md
+146-1Lines changed: 146 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -287,26 +287,171 @@ Select the value and create the policy as required. For example, you might want
287
287
288
288
### Checking for client capabilities
289
289
290
+
The client capabilities claim (`xms_cc`) indicate whether a client application can satisfy the claims challenge generated by a conditional access policy. To obtain this claim in an access token, we enable the `clientCapabilities` configuration option in [authConfig.js](./SPA/src/authConfig.js):
The `routeGuard` middleware checks the mock database for any auth context entries, and inspects the access token in the authorization header of the incoming request to see if it contains the necessary claims. If it does, it passes the request to the next middleware in chain. If it doesn't, the `checkForRequiredAuthContext` middleware takes over. This is shown in [routeGuard.js](./API/utils/routeGuard.js):
320
+
296
321
```javascript
322
+
constauthContextGuard= (req, res, next) => {
323
+
constacrs=AuthContext.getAuthContexts(); // get the current auth contexts from db
324
+
325
+
// if there is no auth context in the db, let the request through
if (accessTokenClaims['xms_cc'] && accessTokenClaims['xms_cc'].includes('CP1')) {
364
+
returntrue;
365
+
}
366
+
367
+
returnfalse;
368
+
}
369
+
```
370
+
371
+
### Generating claims challenge
372
+
373
+
If there is an auth context entry in the mock database and the incoming request does not contain an access token with the necessary claims, the web API needs to create a **claims challenge** and send it to client application to allow the user to satisfy the challenge (for instance, perform multi-factor authentication). This is shown in [claimsManager.js](./API/utils/claimsManager.js):
constmessage="The presented access tokens had insufficient claims. Please request for claims designated in the www-authentication header and try again.";
388
+
389
+
return {
390
+
headers,
391
+
statusCode,
392
+
message
393
+
}
394
+
}
304
395
```
305
396
306
397
### Handling claims challenge
307
398
399
+
Once the client app receives the claims challenge, it needs to present the user with a prompt for satisfying the challenge via Azure AD authorization endpoint. To do so, we use MSAL's `acquireTokenPopup()` API and provide the claims challenge as a parameter in the token request. This is shown in [fetch.js](./SPA/src/fetch.js), where we handle the response from a HTTP DELETE request the to web API with the `handleClaimsChallenge` method:
0 commit comments