@@ -105,11 +105,22 @@ When these conditions are met, the app can extract the claims challenge from the
105
105
106
106
```javascript
107
107
const authenticateHeader = response .headers .get ('www-authenticate' );
108
- const claimsChallenge = authenticateHeader
109
- .split (' ' )
110
- .find ((entry ) => entry .includes ('claims=' ))
111
- .split ('claims="' )[1 ]
112
- .split ('",' )[0 ];
108
+ const claimsChallenge = parseChallenges (authenticateHeader ).claims ;
109
+
110
+ // ...
111
+
112
+ function parseChallenges (header ) {
113
+ const schemeSeparator = header .indexOf (' ' );
114
+ const challenges = header .substring (schemeSeparator + 1 ).split (',' );
115
+ const challengeMap = {};
116
+
117
+ challenges .forEach ((challenge ) => {
118
+ const [key , value ] = challenge .split ('=' );
119
+ challengeMap [key .trim ()] = window .decodeURI (value .replace (/ ['"]+/g, ''));
120
+ });
121
+
122
+ return challengeMap ;
123
+ }
113
124
```
114
125
115
126
Your app would then use the claims challenge to acquire a new access token for the resource .
@@ -118,22 +129,19 @@ Your app would then use the claims challenge to acquire a new access token for t
118
129
let tokenResponse ;
119
130
120
131
try {
121
-
122
132
tokenResponse = await msalInstance .acquireTokenSilent ({
123
- claims : window .atob (claimsChallenge ), // decode the base64 string
124
- scopes : scopes , // e.g ['User.Read', 'Contacts.Read']
125
- account : account , // current active account
126
- });
133
+ claims : window .atob (claimsChallenge ), // decode the base64 string
134
+ scopes : scopes , // e.g ['User.Read', 'Contacts.Read']
135
+ account : account , // current active account
136
+ });
127
137
128
138
} catch (error ) {
129
-
130
139
if (error instanceof InteractionRequiredAuthError ) {
131
-
132
140
tokenResponse = await msalInstance .acquireTokenPopup ({
133
- claims : window .atob (claimsChallenge ), // decode the base64 string
134
- scopes : scopes , // e.g ['User.Read', 'Contacts.Read']
135
- account : account , // current active account
136
- });
141
+ claims : window .atob (claimsChallenge ), // decode the base64 string
142
+ scopes : scopes , // e.g ['User.Read', 'Contacts.Read']
143
+ account : account , // current active account
144
+ });
137
145
}
138
146
139
147
}
0 commit comments