如果您有 id_token 个 MSAL,则获得 access_token
Get access_token if you have id_token MSAL
我正在使用 MSAL 库来授权我的 SPA。
初始化:
msUserAgent = new Msal.UserAgentApplication(idApp, null, null, {});
调用登录弹出窗口:
msUserAgent.loginPopup(['user.read'])
.then((res) => console.log(res))
.catch((err) => console.log(err));
设置我的凭据后,弹出窗口没有关闭,而是重定向到主页。然后 catch 根本没有被调用。
github 上关于此的问题:https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/174
重定向后,我的 URL(在弹出窗口中)有 id_token(jwt-token),但此页面尚未初始化 msUserAgent
。它动态处理,我在用户点击后初始化 msUserAgent
(从后端获取的 idApp)
问题:
当我有 id_token (jwt-token) 时,我可以通过使用 MSAL lib 获得 access_token 吗?
谢谢
要获得 access_token 接下来需要做的事情:
- 在您被重定向的页面上。您需要加载 MSAL 脚本
- msUserAgent 需要在加载所有脚本后自动初始化
- MSAL 检查 uri 中是否存在 JWT 令牌(重定向后),如果存在,立即发送静默请求并获取 access_token 并保存到 sessionStorage(您可以在选项中更改为 localStorage)
我正在使用 MSAL 库来授权我的 SPA。 初始化:
msUserAgent = new Msal.UserAgentApplication(idApp, null, null, {});
调用登录弹出窗口:
msUserAgent.loginPopup(['user.read'])
.then((res) => console.log(res))
.catch((err) => console.log(err));
设置我的凭据后,弹出窗口没有关闭,而是重定向到主页。然后 catch 根本没有被调用。 github 上关于此的问题:https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/174
重定向后,我的 URL(在弹出窗口中)有 id_token(jwt-token),但此页面尚未初始化 msUserAgent
。它动态处理,我在用户点击后初始化 msUserAgent
(从后端获取的 idApp)
问题: 当我有 id_token (jwt-token) 时,我可以通过使用 MSAL lib 获得 access_token 吗?
谢谢
要获得 access_token 接下来需要做的事情:
- 在您被重定向的页面上。您需要加载 MSAL 脚本
- msUserAgent 需要在加载所有脚本后自动初始化
- MSAL 检查 uri 中是否存在 JWT 令牌(重定向后),如果存在,立即发送静默请求并获取 access_token 并保存到 sessionStorage(您可以在选项中更改为 localStorage)