Is it possible to use MSAL.js to get refresh token?

前端 未结 3 1687
春和景丽
春和景丽 2020-12-17 17:29

I want to integrate with Miscrosoft Outlook. I am able to login with MSAL.js and get an access token, but I am not able to get a refresh token. Is there a way to do it?

相关标签:
3条回答
  • 2020-12-17 17:49

    I couldn't find any answer in the MSAL.js documentation, however this source code comment suggests you can renew a token manually by passing only the clientId as your scope to acquireTokenSilent.

    To renew idToken, please pass clientId as the only scope in the Authentication Parameters

    0 讨论(0)
  • 2020-12-17 17:54

    I use msal v1.4.0

    I remove 2 keys in storage (see picture) then call acquireTokenSilent again to get new access token. Code to remove those 2 keys:

    const keys = Object.keys(sessionStorage).filter(x => x.indexOf('authority') > 0)
    keys.forEach(x => sessionStorage.removeItem(x))
    
    0 讨论(0)
  • 2020-12-17 17:57

    I'll assume that since you're using the MSAL.js (https://github.com/AzureAD/microsoft-authentication-library-for-js) that you're using implicit flow for authentication and authorization.

    Implicit flow doesn't support refresh tokens, but you can request a new token silently. This is done similarly to how you request the token (id or access) in the first place. Unfortunately, I haven't found that MSAL.js does this transparently and I've needed to detect expired tokens and request the new tokens in my code. You can read more about refreshing tokens here.

    Alternatively, if what you're implementing allows you to use one of the other MSAL libraries (for example, the .Net one) then you can use one of the other OAuth flows that explicitly support refresh tokens.

    0 讨论(0)
提交回复
热议问题