Sign in Azure AD using AppAuth

I’ve opened a topic before for using the expo-app-auth package with Microsoft Azure Login but did not get any solution. Link to the previous topic: Sign in Azure AD using AppAuth package

But now I was able to get the package to work with Microsoft Provider (hotmail, outlook, live …)

The problem was that the Microsoft APIs were not updated to version 2. And here’s the code for the access token response:

const tokenResponse = await AppAuth.authAsync({
issuer: “https://login.microsoftonline.com/common/v2.0”,
clientId: YOUR_CLIENT_ID,
redirectUrl: AppAuth.OAuthRedirect + ‘://oauthredirect’,
scopes: [
“openid”,
“profile”,
“offline_access”,
“user.read”,
“mail.read”
]
});

This redirect URI is for the Expo Client apps (should be added also in the Azure App Redirect URIs), but in case of standalone apps, it is either the android.package (for Android) or ios.bundleIdentifier (for iOS) value from your app.json. Check the package documentation. The scopes also are according to the required access for your application.

Hope this post helps! :slight_smile:

1 Like

Working Fine, what error are you facing?

Hi Onaggar, thanks for sharing it.

I’m facing this error bellow, do you have any idea how to solve it?

ERR_APP_AUTH: JSON error parsing document at ‘https://login.microsoftonline.com/common/v2.0/.well-known/openid-configuration’: Invalid URL: issuer

My config settings are:
const microsoftConfig = {
issuer: ‘https://login.microsoftonline.com/common/v2.0’,
clientId: microsoft_id,
clientSecret: microsoft_secret,
redirectUrl: ${AppAuth.OAuthRedirect}://oauthredirect,
scopes: [‘openid’, ‘profile’, ‘offline_access’, ‘user.read’],
};

Thanks in advance.

Did you add “host.exp.exponent://oauthredirect” to your Azure Application Redirect URIs ?

Yep, also tried adding others uri too but nothing worked =/

I changed the issuer to: https://login.microsoftonline.com/${tenant_id}/v2.0/, and now the popup appears, but nothing returns after I accept the login

I don’t know if you ever resolved this, but I am posting this for anyone else that has wrestled with it.

I also wasn’t getting a response after login, so I changed the redirect URL.

What seems to work for me in development in the expo app is:

Azure Portal redirect:
host.exp.exponent://expo.io/@user-name/slug
App redirect:
AppAuth.OauthRedirect+’://expo.io/@user-name/slug’

If Microsoft doesn’t allow you to use that from their interface, edit the JSON in the Manifest with the redirect URL. (Microsoft doesn’t appear to allow the ‘@’ symbol)

“replyUrlsWithType”: [
{
“url”: “host.exp.exponent://expo.io/@user-name/slug”,
“type”: “InstalledClient”
}]

2 Likes

Thank you! I had been battling this for ages, and it’s working now.

Glad to hear!