Skip to content

Commit ec944ab

Browse files
Merge pull request #230746 from salman90/update-error-doc
Update the code snippets
2 parents 299c886 + 65c9b57 commit ec944ab

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

articles/active-directory/develop/msal-error-handling-js.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,20 @@ The following error types are available:
5454

5555
- `InteractionRequiredAuthError`: Error class, extends `ServerError` to represent server errors, which require an interactive call. This error is thrown by `acquireTokenSilent` if the user is required to interact with the server to provide credentials or consent for authentication/authorization. Error codes include `"interaction_required"`, `"login_required"`, and `"consent_required"`.
5656

57-
For error handling in authentication flows with redirect methods (`loginRedirect`, `acquireTokenRedirect`), you'll need to register the callback, which is called with success or failure after the redirect using `handleRedirectCallback()` method as follows:
57+
For error handling in authentication flows with redirect methods (`loginRedirect`, `acquireTokenRedirect`), you'll need to handle the redirect promise, which is called with success or failure after the redirect using the `handleRedirectPromise()` method as follows:
5858

5959
```javascript
60-
function authCallback(error, response) {
61-
//handle redirect response
62-
}
63-
64-
var myMSALObj = new Msal.UserAgentApplication(msalConfig);
60+
const msal = require('@azure/msal-browser');
61+
const myMSALObj = new msal.PublicClientApplication(msalConfig);
6562

6663
// Register Callbacks for redirect flow
67-
myMSALObj.handleRedirectCallback(authCallback);
64+
myMSALObj.handleRedirectPromise()
65+
.then(function (response) {
66+
//success response
67+
})
68+
.catch((error) => {
69+
console.log(error);
70+
})
6871
myMSALObj.acquireTokenRedirect(request);
6972
```
7073

@@ -97,10 +100,8 @@ myMSALObj.acquireTokenSilent(request).then(function (response) {
97100
// call API
98101
}).catch( function (error) {
99102
// call acquireTokenPopup in case of acquireTokenSilent failure
100-
// due to consent or interaction required
101-
if (error.errorCode === "consent_required"
102-
|| error.errorCode === "interaction_required"
103-
|| error.errorCode === "login_required") {
103+
// due to interaction required
104+
if (error instanceof InteractionRequiredAuthError) {
104105
myMSALObj.acquireTokenPopup(request).then(
105106
function (response) {
106107
// call API
@@ -123,10 +124,9 @@ myMSALObj.acquireTokenSilent(accessTokenRequest).then(function(accessTokenRespon
123124
}).catch(function(error) {
124125
if (error instanceof InteractionRequiredAuthError) {
125126

126-
// extract, if exists, claims from error message
127-
if (error.ErrorMessage.claims) {
128-
accessTokenRequest.claimsRequest = JSON.stringify(error.ErrorMessage.claims);
129-
}
127+
// extract, if exists, claims from the error object
128+
if (error.claims) {
129+
accessTokenRequest.claims = error.claims,
130130

131131
// call acquireTokenPopup in case of InteractionRequiredAuthError failure
132132
myMSALObj.acquireTokenPopup(accessTokenRequest).then(function(accessTokenResponse) {
@@ -140,13 +140,12 @@ myMSALObj.acquireTokenSilent(accessTokenRequest).then(function(accessTokenRespon
140140
141141
Interactively acquiring the token prompts the user and gives them the opportunity to satisfy the required Conditional Access policy.
142142
143-
When calling an API requiring Conditional Access, you can receive a claims challenge in the error from the API. In this case, you can pass the claims returned in the error to the `claimsRequest` field of the `AuthenticationParameters.ts` class to satisfy the appropriate policy.
144-
145-
See [Requesting Additional Claims](active-directory-optional-claims.md) for more detail.
143+
When calling an API requiring Conditional Access, you can receive a claims challenge in the error from the API. In this case, you can pass the claims returned in the error to the `claims` parameter in the [access token request object](https://learn.microsoft.com/azure/active-directory/develop/msal-js-pass-custom-state-authentication-request) to satisfy the appropriate policy.
146144
145+
See [How to use Continuous Access Evaluation enabled APIs in your applications](./app-resilience-continuous-access-evaluation.md) for more detail.
147146
148147
[!INCLUDE [Active directory error handling retries](../../../includes/active-directory-develop-error-handling-retries.md)]
149148
150149
## Next steps
151150
152-
Consider enabling [Logging in MSAL.js](msal-logging-js.md) to help you diagnose and debug issues.
151+
Consider enabling [Logging in MSAL.js](msal-logging-js.md) to help you diagnose and debug issues

0 commit comments

Comments
 (0)