1

I'm using redirect flow to perform authenticate flow but sometimes after login redirect will met a canceled process when acquireTokenSilent

here is my login process

public async componentDidMount() {

    msalApp.handleRedirectCallback(error => {
      if (error) {
        const errorMessage = error.errorMessage ? error.errorMessage : "Unable to acquire access token.";
        // setState works as long as navigateToLoginRequestUrl: false
      }
    });

    if (!msalApp.getAccount()) {
      if (isMobile) {
        msalApp.loginRedirect(GRAPH_REQUESTS.CDA);
      }
      else {
        const response = await msalApp
          .loginPopup(GRAPH_REQUESTS.CDA)
          .catch(error => {
            ;
          });
        console.log("after login" + response);
        this.props.onFetchTemplate();
      }
    } else { this.props.onFetchTemplate(); }
  }

get access token function

export const getTokenRedirect = (): Promise<string> => {
    return new Promise((resolve, reject) => {
        msalApp.acquireTokenSilent({
            scopes: [GRAPH_SCOPES.SITE_TEMPLATE]//,loginHint: JSON.parse((JSON.stringify(msalApp.getAccount(), null, 4))).name
        })
            .then(resp => resolve(resp.accessToken)).catch(error => {
                if (requiresInteraction(error.errorCode)) {
                    msalApp.acquireTokenRedirect(GRAPH_REQUESTS.CDA);
                }
            });
    });
};

and also my config

export const authRedirect = {
    clientId: "****",
    authority: "https://login.microsoftonline.com/tennatid",
    validateAuthority: true,
    postLogoutRedirectUri: "https://myweburl",
    navigateToLoginRequestUrl: false
};

export const msalApp = new UserAgentApplication({
    auth: isMobile == true ? authRedirect : auth,
    cache: {
        cacheLocation: "sessionStorage",
        storeAuthStateInCookie: isIE()
    },
    system: {
        navigateFrameWait: 0
    }
});

and this error happen,the authorize process when get token canceled by MS I think.I could not reproduce it in localhost. enter image description here

Kevin YANG
  • 411
  • 2
  • 8
  • 23
  • It works well in local,and also login redirect works well,but when I tried to acquireTokenSilent When doing authorization, sometimes this step succeed and sometimes fail,just in the screenshot with no other logs. – Kevin YANG Jun 12 '20 at 08:20
  • What is the in the response of the red line item? The response data will show the reason – Jas Suri - MSFT Jun 15 '20 at 10:05
  • Sometimes a normal token is returned, but an error code is returned very frequently,`token_renewal_error` – Kevin YANG Jun 16 '20 at 03:19
  • Yes,regarding to this issue,I still do not solve it.Just do a redirect login when failed to get token to invoid this issue.@Nishant - MSFT Identity – Kevin YANG Aug 13 '20 at 05:28
  • why did you set navigateFrameWait to 0 ? It could be causing this problem – Vladyslav Goloshchapov Dec 17 '20 at 10:41

0 Answers0