Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support get access token and token renewal #7595

Merged
merged 11 commits into from
Feb 27, 2025

Conversation

yongdiw
Copy link

@yongdiw yongdiw commented Feb 25, 2025

This PR is to add support for getting an access token in the msal-custom-auth library.

Why:

  1. After the user complete sign in process, the user could use getAccessToken to acquire token.
  2. When acquiring token, the flow will look like below:
    1. Look up browser cache to see if there is any cached access token.
      1. If access token found and it is valid (not expired), return it.
      2. If access token found but expired, renew it.
      3. If access token not found, renew it.
    2. Renew access token - Look up browser cache and see if there is any cached refresh token.
      1. If cached refresh token found and it is valid, call POST /token endpoint to get a new access token. Once it is done, return the new tokens.
      2. If any error when during calling /token endpoint, throw error.
      3. If cached refresh token found but expired, throw error.
      4. If cached refresh token not found, throw error.'
    3. If throw error in the end, user should restart sign-in process again.
  3. If forceRefresh=true, then skip cache look up and only execute token renew.
  4. If no input for scopes, then use default scopes. Otherwise, it will be used during cache lookup and renew token (as request body). It has to be at least a subset of cached access token scope.

What:

  1. In CustomAuthSilentCacheClient, reuse SilentFlowClient originally defined in msal-browser to handle the flow mentioned above.
  2. Add tests for CustomAuthSilentCacheClient to ensure the flow works as expected
  3. Update CustomAuthAuthority to create AuthorityMetadataEntity and set into cache storage. This is used during token look up and calling correct /token endpoint for token renewal.

@github-actions github-actions bot removed the msal-browser Related to msal-browser package label Feb 27, 2025
@yongdiw yongdiw merged commit 74f845f into custom-auth/main Feb 27, 2025
2 of 6 checks passed
@yongdiw yongdiw deleted the custom-auth/get-token branch February 27, 2025 17:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants