[ ] 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:
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 })
}
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
});
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.
Most helpful comment
It seems to me that you have forgotten to call the
handleRedirectCallbackfunction on yourmsalInstance. 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.
More on this here.