简体   繁体   English

如果您有id_token MSAL,则获取access_token

[英]Get access_token if you have id_token MSAL

I'm using MSAL lib for authorize my SPA. 我正在使用MSAL lib授权我的SPA。 Init: 在里面:

msUserAgent = new Msal.UserAgentApplication(idApp, null, null, {});

Call loginPopup: 呼叫loginPopup:

msUserAgent.loginPopup(['user.read'])
    .then((res) => console.log(res))
    .catch((err) => console.log(err));

after set my credentials, popUp not closing, but redirect to main page. 设置好凭据后,popUp不会关闭,但会重定向到主页。 Then and catch not called at all. 然后,抓住根本没有被召唤。 Issue on github about this: https://github.com/AzureAD/microsoft-authentication-library-for-js/issues/174 关于此的github问题: https : //github.com/AzureAD/microsoft-authentication-library-for-js/issues/174

After redirect, my URL (in popup) has id_token (jwt-token), but this page doesn't have initialized msUserAgent yet. 重定向后,我的URL(在弹出窗口中)具有id_token(jwt-token),但是此页面尚未初始化msUserAgent It dynamically process, I initialize msUserAgent after user click (idApp getting from backend) 它动态处理,我在用户单击后初始化msUserAgent (从后端获取idApp)

Question: Can I get access_token when I have id_token (jwt-token) by using MSAL lib? 问题: 使用MSAL lib获得id_token(jwt-token)后,我能否获得access_token?

Thanks 谢谢

for getting access_token need to do next: 获取access_token下一步需要执行以下操作:

  1. On page where you are being redirected. 在您将被重定向到的页面上。 You need to have loaded MSAL script 您需要加载MSAL脚本
  2. msUserAgent need to auto init after all scripts will be loaded 加载所有脚本后,msUserAgent需要自动初始化
  3. MSAL checking if JWT token present in uri (after redirect), and if it exists, immediately send silent request and get access_token and save to sessionStorage (you can change to localStorage in options) MSAL检查URI(重定向后)中是否存在JWT令牌,如果存在,请立即发送静默请求并获取access_token并保存到sessionStorage(您可以在选项中更改为localStorage)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从现有的id_token获取Auth0 access_token - Get Auth0 access_token from existing id_token 尝试使用 ADAL.js AuthenticationContext 获取访问令牌时,access_token 与 id_token 相同吗? - access_token same as id_token when trying to acquire access token with ADAL.js AuthenticationContext? Auth0中id_token和access_token有什么区别 - What is the difference between id_token and access_token in Auth0 如何使用 'id_token'、'access_token'、expiry 等直接创建 userManager? - How can create userManager directly with 'id_token', 'access_token', expiry etc.? 使用Azure AD身份验证库(角度5中的ADAL)获取Id_token,但是如何从Id_token获取访问令牌? - getting Id_token using Azure AD Authentication Library(ADAL in angular 5), but how to get access token from Id_token? 在什么触发器上我可以通过 MSAL 的 msalObj.acquireTokenSilent() 方法静默获取 id_token? - On what trigger can I get an id_token silently via msalObj.acquireTokenSilent() method of MSAL? Angular的MSAL / Microsoft授权问题:如何验证id_token? - MSAL/ Microsoft Authorization problem with Angular: How to validate id_token? 无法获得access_token - Cant get access_token 谷歌 oauth2 获取 id_token - Google oauth2 get id_token 从id_token获取Google OAuth访问令牌 - Getting a Google OAuth access token from an id_token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM