我正在尝试找出如何正确使用msal来通过重定向方法获取令牌。
我具有以下功能:
function acquireTokenRedirect() {
const params = {
redirectUri: 'http://localhost:8080/admin/',
scopes: ['user.read']
};
console.log('Acquire token via redirect');
msal.acquireTokenRedirect(params);
}
和回调:
msal.handleRedirectCallback((error, response) => {
console.log('Redirect call back is called');
});
当我调用该方法时,这是我在Chrome控制台中得到的:
Acquire token via redirect
Navigated to http://localhost:8080/admin/
Redirect call back is called
GET http://localhost:8080/ 404 (Not Found)
Navigated to http://localhost:8080/
当我特别告诉它重定向到http://localhost:8080/
时,为什么它重定向到http://localhost:8080/admin/
?
MSAL配置为使用redirectURI:http://localhost:8080/admin/
,并且在Azure门户中为项目指定了相同的重定向。
相比之下,msal.loginRedirect()
重定向到正确的URI。
答案 0 :(得分:0)
我想这与本期的解决方案有关:
为避免额外的重定向,我需要做的是设置 Auth config中的“ navigateToLoginRequestUrl ”参数设置为false。这解决了 我的问题。
参考:msal in React SPA - use access token received from AcquireTokenRedirect
让我知道是否有帮助