I'm currently setting up ADD with MSAL for my app. The issue I am running into is that the api is set to accept Azure AD V1 tokens, but with my current MSAL setup I keep receiving an Azure AD V2.
Other people in my team are using ADAL, but we want to migrate to MSAL. I'm sure I'm doing something wrong, as it seems hard to believe there is no backwards compatibility.
This is my Msal Config:
import * as Msal from 'msal';
export const applicationConfig = {
clientID: process.env.REACT_APP_MSAL_CLIENT_ID,
authority: process.env.REACT_APP_AUTHORITY_TENANT,
graphScopes: ['user.read'],
graphEndpoint: process.env.REACT_APP_GRAPH_ENDPOINT,
};
/**
* will get the call back once the API is complete
* (either complete or failure), redirects flows.
* Is called after the authentication request is completed
* successfully/failure
*
* @param {*} errorDesc
* @param {*} token
* @param {*} error
* @param {*} tokenType
*/
const tokenReceivedCallback = async (errorDesc, token, errorMsg) => {
try {
if (token) console.log('Success!');
} catch (error) {
throw new Error(`${errorMsg}:${errorDesc}`);
}
};
/**
* Instantiate UserAgentApplication
*/
const userAgentApplication = new Msal.UserAgentApplication(
applicationConfig.clientID,
applicationConfig.authority,
tokenReceivedCallback,
{
cacheLocation: process.env.REACT_APP_CACHE_LOCATION,
redirectUri: process.env.REACT_APP_REDIRECT_URI,
},
);
/**
* Log user in
* Checks if there is no user and if there is no
* callback occuring within the window url which throws into
* infinite loop, then login, and redirect to SSO login
* @param {*} graphScopes
*/
export const signIn = async graphScopes => {
console.log(graphScopes);
/**
* avoid duplicate code execution on page load in case of iframe and popup window
*/
if (!userAgentApplication.getUser() && !userAgentApplication.isCallback(window.location.hash)) {
/**
* login site, and go directly to SSO
*/
await userAgentApplication.loginRedirect(graphScopes, process.env.REACT_APP_DOMAIN);
/**
* acquireTokenSilent method makes a silent request to ADD to obtain an access token.
* ADD returns an access token containing the user consented scopes to allow
* the app to securely call the api
*/
await userAgentApplication.acquireTokenSilent(graphScopes);
}
};
/**
* Logs user out
*/
export const logOut = () => userAgentApplication.logout();
This is what I get when I use jwt.ms:
Thanks in advance!
loginRedirect()
belongs to theMSAL()
object. I request my token fromgraph.windows
– aromanarguello