How to get auth code using msal
See original GitHub issueCore Library
MSAL.js v2 (@azure/msal-browser)
Wrapper Library
MSAL React (@azure/msal-react)
Documentation Location
https://github.com/AzureAD/microsoft-authentication-library-for-js
Description
is it possible to request auth code (https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth2-auth-code-flow) using this library for React? If so, is it possible for someone to give me a code sample? I’ve tried looking around but have had a really difficult time getting the auth code.
By using this Azure sample and following this tutorial, I’m able to get the accessToken but can’t figure out how to get the auth code (the response is returning null for code: null
) to pass to our backend.
Currently, we’re using this code snippet to show a popup and get the accessToken in the response. Is it possible to configure the code snippet below to only get the auth code so we can pass that to our backend to use and exchange for tokens?
instance.acquireTokenPopup(loginRequest).then(response => {
}).catch(e => {
})
Issue Analytics
- State:
- Created a year ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top GitHub Comments
@mikeyyyzhao msal-browser/msal-react does not expose the authorization code to the developer, and the authorization code obtained for your frontend shouldn’t be passed to your backend. If you need to authenticate users to your backend, you should use msal-node instead. If you need to authenticate users on both frontend and backend, you might want to look into the hybrid spa auth code sample here.
@derisen I have the same issue as @logan-jobzmall. I have an angular based spa app where I want the user to grant authorization for their personal Outlook Calendar so that my back end server can then add/update events on their behalf on an ongoing, non-interactive basis. This is easy in Google where I get an AccessCode on the client that I then send to the server to trade for an AccessToken/RefreshToken, then store the RefreshToken for later API usage without user interaction.
Is this even possible with MSAL/MS Graph?