We're building an Ionic 4 app with angular 7 and we want to authenticate against Azure AD v2 endpoints. We're using msal-angular wrapper for the msal.js library. We're hitting the endpoints successfully and the authentication provider responds with a token in our callback.
Here begins our problem. The msal library doesn't handle this token automatically in a mobile-app context, so we have to try and handle this manually. When we're debugging the application in a browser, the msal library automatically saves the token and we're logged in correctly.
In order to redirect to a page within our mobile application we're using Applinks/Deeplinks cordova plugin, to provide a callback URI that is accepted by the authentication provider as a valid URI and enables us to redirect to the application (and to the correct page in the application). However with Deeplinks, we're hitting our callback, but the MSAL library is not able to identify the callback and thus is not able to continue it's login process to save the token and set it's state to logged in (we're leveraging this library to also guard routes in our application).
This works as intended without Deeplinks debugging in a browser. How can we make the MSAL library continue with it's login-process when the callback is hit?
MSAL config:
MsalModule.forRoot({
clientID: '******',
authority: "https://login.microsoftonline.com/********", // (Optional) It is the authority URL as described in the configuration section above to support account types. The default authority is https://login.microsoftonline.com/common.
validateAuthority: true,
redirectUri: "https://example.com/callback",
cacheLocation : "localStorage",
postLogoutRedirectUri: "https://example.com/home",
navigateToLoginRequestUrl: false,
popUp: false,
consentScopes: [ "user.read", "api://*************/user_read"],
unprotectedResources: ["https://www.microsoft.com/en-us/"],
correlationId: '1234',
piiLoggingEnabled: true
})
Deeplinks:
this.platform.ready().then(() => {
this.deeplinks.route({
'/home': HomePage,
'/callback': CallbackPage
}).subscribe((match) => {
const idToken = match.$link.fragment;
this.router.navigate(['/callback', {key: idToken}])
},
(nomatch) => {
console.error('Got a deeplink that didn\'t match', nomatch);
});
});