Microsoft 单点登录 - react-aad-msal 库 - 无法获取访问令牌
Microsoft single sign on - react-aad-msal library - can't get access token
我正在开发一个带有 React 前端和 .NET CORE 3.1 后端的 Web 应用程序,并被要求添加 Azure AD 单点登录功能。我正在使用 react-aad-msal 库 (https://www.npmjs.com/package/react-aad-msal)。我正在调用 MsalAuthProvider.getAccessToken() 并收到此错误:
Can't construct an AccessTokenResponse from a AuthResponse that has a token type of "id_token".
谁能帮帮我?
有人吗?顺便提一句。 getAccessToken() 实际上在标准 msal 库中,如果有帮助的话。
我自己找到了一个解决方案,方法是进入 packages.json 并降低“依赖项”中“msal”的版本号,如下所示:
"msal": "~1.3.0",
更改 authProvider 中的范围。
export const authProvider = new MsalAuthProvider(
{
auth: {
authority: 'https://login.microsoftonline.com/5555555-5555-5555-5555-555555555555',
clientId: 'AAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA',
postLogoutRedirectUri: 'http://localhost:3000/signin',
redirectUri: 'http://localhost:3000/signin',
validateAuthority: true,
navigateToLoginRequestUrl: false
},
system: {
logger: new Logger(
(logLevel, message, containsPii) => {
console.log("[MSAL]", message);
},
{
level: LogLevel.Verbose,
piiLoggingEnabled: false
}
)
},
cache: {
cacheLocation: "sessionStorage",
storeAuthStateInCookie: true
}
},
{
scopes: ["openid", "profile", "user.read"] // <<<-----------|
},
{
loginType: LoginType.Popup,
tokenRefreshUri: window.location.origin + "/auth.html"
}
);
我正在开发一个带有 React 前端和 .NET CORE 3.1 后端的 Web 应用程序,并被要求添加 Azure AD 单点登录功能。我正在使用 react-aad-msal 库 (https://www.npmjs.com/package/react-aad-msal)。我正在调用 MsalAuthProvider.getAccessToken() 并收到此错误:
Can't construct an AccessTokenResponse from a AuthResponse that has a token type of "id_token".
谁能帮帮我?
有人吗?顺便提一句。 getAccessToken() 实际上在标准 msal 库中,如果有帮助的话。
我自己找到了一个解决方案,方法是进入 packages.json 并降低“依赖项”中“msal”的版本号,如下所示:
"msal": "~1.3.0",
更改 authProvider 中的范围。
export const authProvider = new MsalAuthProvider(
{
auth: {
authority: 'https://login.microsoftonline.com/5555555-5555-5555-5555-555555555555',
clientId: 'AAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA',
postLogoutRedirectUri: 'http://localhost:3000/signin',
redirectUri: 'http://localhost:3000/signin',
validateAuthority: true,
navigateToLoginRequestUrl: false
},
system: {
logger: new Logger(
(logLevel, message, containsPii) => {
console.log("[MSAL]", message);
},
{
level: LogLevel.Verbose,
piiLoggingEnabled: false
}
)
},
cache: {
cacheLocation: "sessionStorage",
storeAuthStateInCookie: true
}
},
{
scopes: ["openid", "profile", "user.read"] // <<<-----------|
},
{
loginType: LoginType.Popup,
tokenRefreshUri: window.location.origin + "/auth.html"
}
);