Microsoft-authentication-library-for-js: loginRedirect() doesn't have a redirect callback

Created on 22 May 2019  路  3Comments  路  Source: AzureAD/microsoft-authentication-library-for-js

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[ x ] Bug report  
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Other... Please describe:

Browser:

  • [x] Chrome version XX
  • [ ] Firefox version XX
  • [ ] IE version XX
  • [ ] Edge version XX
  • [ ] Safari version XX

Library version


Library version: 1.0.0


## Current behavior

msalInstance.loginRedirect({ scopes })

Produces the following error: ClientConfigurationError: No redirect callbacks have been set. Please call setRedirectCallbacks() with the appropriate function arguments before continuing. More information is available here: https://github.com/AzureAD/microsoft-authentication-library-for-js/wiki/-basics.

## Expected behavior

It works the same way loginPopup works (redirect uri is fetched from my settings in Azure AD)


## Minimal reproduction of the problem with instructions


  const authConfig = {
    auth: {
      clientId,
      authority,
      navigateToLoginRequestUrl: false
    },
    cache: {
      cacheLocation: 'localStorage',
    }
  }

   const msalInstance = new Msal.UserAgentApplication(authConfig)

    if(msalInstance.getAccount()) {
      msalInstance.acquireTokenSilent({ scopes })
      .then((res) => {
        console.log('Silent Login Success: ', res)

        // set token in sessionStorage
        const { accessToken, expiresOn } = res
        sessionStorage.setItem('access_token', accessToken)
        sessionStorage.setItem('token_expiration', expiresOn)

        // get user info from graph api
        getUserInfo(accessToken)
      })
      .catch((err) => console.log(err))
    } else {
      msalInstance.loginRedirect({ scopes })
    }


Most helpful comment

It seems to me that you have forgotten to call the handleRedirectCallback function on your msalInstance. The function takes a function with two parameters as a parameter, and calls it after the redirect.

If you write the code like this, it should work as expected.

const msalInstance = new Msal.UserAgentApplication(authConfig);
msalInstance.handleRedirectCallback((error, response) => {
  // if error is not null, something went wrong
  // if not, response is a successful login response
});

More on this here.

All 3 comments

It seems to me that you have forgotten to call the handleRedirectCallback function on your msalInstance. The function takes a function with two parameters as a parameter, and calls it after the redirect.

If you write the code like this, it should work as expected.

const msalInstance = new Msal.UserAgentApplication(authConfig);
msalInstance.handleRedirectCallback((error, response) => {
  // if error is not null, something went wrong
  // if not, response is a successful login response
});

More on this here.

Can someone add this to the MSALJS documentation.

@ritwbanerjee The configurartion section in the link @raikoss added above: msal release notes has the details. Also the SPA documentation also included this detail.

Closing this ticket.

Was this page helpful?
0 / 5 - 0 ratings