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

Make it easier to refresh tokens on the server without distributed cache for better serverless support #7573

Open
mastoj opened this issue Feb 17, 2025 · 0 comments
Labels
confidential-client Issues regarding ConfidentialClientApplications feature-unconfirmed msal-node Related to msal-node package Needs: Attention 👋 Awaiting response from the MSAL.js team question Customer is asking for a clarification, use case or information.

Comments

@mastoj
Copy link

mastoj commented Feb 17, 2025

Core Library

MSAL Node (@azure/msal-node)

Wrapper Library

Not Applicable

Public or Confidential Client?

Confidential

Description

More and more people are using next.js, but this should also be applicable to a asp.net application following the same pattern, but I will take it from the next.js point of view.

In next.js, it is very common to do the token exchange on the server and less work on the client. This is all good and something that is fairly easy to set up. What is not easy is the refresh of tokens. I actually expected to get some refresh token in the response that I could set on a refresh_token cookie, but that does not seem to be the case. Instead it seems like this example, https://github.com/AzureAD/microsoft-authentication-library-for-js/tree/dev/samples/msal-node-samples, focus on setting up a cache that is durable, but in my mind that just leads to extra complexity.

What is the reason to not just expose the refresh token and then in frameworks like next.js, the server can request new tokens using the refresh token in a middleware if needed before executing a function. This way it would be much easier to have the authorize callback function in a serverless environment for example.

I think some of the steps trying to simplify the flows have made it more complex than needed and would love to see a simpler version without as many abstractions.

The flow I picture in my head

  • Login client request -> Server - responds with authorize url
  • User follows authorize url and gets code back
  • User make a request with code -> Server - responds with relevenant cookies, one should be refresh_token
  • When access token expires, but refresh token is valid -> middleware refreshes the access token before executing a function
@mastoj mastoj added feature-unconfirmed question Customer is asking for a clarification, use case or information. labels Feb 17, 2025
@github-actions github-actions bot added confidential-client Issues regarding ConfidentialClientApplications msal-node Related to msal-node package labels Feb 17, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: Attention 👋 Awaiting response from the MSAL.js team label Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confidential-client Issues regarding ConfidentialClientApplications feature-unconfirmed msal-node Related to msal-node package Needs: Attention 👋 Awaiting response from the MSAL.js team question Customer is asking for a clarification, use case or information.
Projects
None yet
Development

No branches or pull requests

1 participant