React-native-app-auth: Authorize never returns after async call

Created on 12 Sep 2019  Â·  12Comments  Â·  Source: FormidableLabs/react-native-app-auth

Issue

I have been trying to implement a solution where the "Reset Password" option is handled when a user is attempting to authorize with my app. I came up with the below, but when this executes the authorize call never returns. It doesn't return with a success or error. I have also noticed this will randomly happen during development when I'm reloading the app several times. It will enter my auth function and never return, thus hanging until I clear cache, clear data and restart the app.

export const auth = () => {
    return async(dispatch) => {
        var resetEndpoint = "https://login.microsoftonline.com/giftwizit.onmicrosoft.com/oauth2/v2.0/authorize?p=B2C_1_secretreset1"
        dispatch(authStart())
        try {
            console.log("in auth function");
            const authState = await authorize(authCfg.config);
            // Store token info in asyncStorage
            dispatch(authStoreToken(authState));
        }catch(error) {
            // dispatch(authFail(error));
            if(error.message.indexOf("AADB2C90118") !== -1){
               await authorize({
                   ...authCfg.config,
                   serviceConfiguration:{
                       ...authCfg.config.serviceConfiguration,
                       authorizationEndpoint: resetEndpoint
                   }
               }).then((result) => {
                   console.log(result);
               }).catch((e) => {
                   console.log(e);
               });
               console.log("Password reset complete");
            }else {
                console.log(error);
            }
        }
    }
}

Environment

  • Your Identity Provider: e.g. IdentityServer 4 / Okta / Azure
    Azure

  • Platform that you're experiencing the issue on: iOS / Android / both
    Android

  • Are you using Expo?
    No

Most helpful comment

Same here

UPD (2hrs ago + 1 iOS Developer):
I have fixed my case:

  1. Azure AD will give you a returnUrl like msauth.[BUNDLE_ID]://auth
  2. It's IMPORTANT to ADD SLASH AT THE END in your config: msauth.[BUNDLE_ID]://auth/
  3. Then it will works.

The problem code is here — https://github.com/openid/AppAuth-iOS/blob/master/Source/OIDAuthorizationService.m#L125
This method on line — https://github.com/openid/AppAuth-iOS/blob/master/Source/OIDAuthorizationService.m#L111 returns false.

You're welcome.

All 12 comments

I want to add that in most, if not all occurrences that the authorize never returning seems to happen only when the debugger is connected.

I am having a similar issue. It returns to the app, but code below the call is never executed.

I am also having the same issue

I`m also having the same issue! help please :(

I am also having the same issue with both Refresh and Authorize.
Is there anyone who can confirm this has happened outside of development?

only seen it when I reload to many times and I can also recreate it while reloading while calling the functions.

Same here

UPD (2hrs ago + 1 iOS Developer):
I have fixed my case:

  1. Azure AD will give you a returnUrl like msauth.[BUNDLE_ID]://auth
  2. It's IMPORTANT to ADD SLASH AT THE END in your config: msauth.[BUNDLE_ID]://auth/
  3. Then it will works.

The problem code is here — https://github.com/openid/AppAuth-iOS/blob/master/Source/OIDAuthorizationService.m#L125
This method on line — https://github.com/openid/AppAuth-iOS/blob/master/Source/OIDAuthorizationService.m#L111 returns false.

You're welcome.

Same here

UPD (2hrs ago + 1 iOS Developer):
I have fixed my case:

  1. Azure AD will give you a returnUrl like msauth.[BUNDLE_ID]://auth
  2. It's IMPORTANT to ADD SLASH AT THE END in your config: msauth.[BUNDLE_ID]://auth/
  3. Then it will works.

The problem code is here — https://github.com/openid/AppAuth-iOS/blob/master/Source/OIDAuthorizationService.m#L125
This method on line — https://github.com/openid/AppAuth-iOS/blob/master/Source/OIDAuthorizationService.m#L111 returns false.

You're welcome.

The original question was for Android.

I have resolved this issue, get familiar with this docs section

I just added below code in adroid/app/src/main/AndroidManifest.xml between <application></application> tags.

    <activity
        android:name="net.openid.appauth.RedirectUriReceiverActivity"
        tools:node="replace">
    <intent-filter>
        <action android:name="android.intent.action.VIEW"/>
        <category android:name="android.intent.category.DEFAULT"/>
        <category android:name="android.intent.category.BROWSABLE"/>
        <data android:scheme="example" android:host="auth" android:pathPrefix="" />
    </intent-filter>
</activity>

In this case, your redirect URL the app will be example://auth

Now it should return all the expected stuff :)

Even though this issue is aimed at Android, we noticed that the iOS solution provided by @isnifer is fixing both our iOS and Android-issues for us.

Normal Microsoft accounts use a redirect URI without a trailing slash
Azure AD accounts use a redirect URI including a trailing slash

Both, however, work with the trailing slash. We have updated our configuration to add the trailing slash and now both Android and iOS workperfectly.

Thanks @isnifer.

@jdegger glad to hear! You're welcome!

@isnifer Thank you so very much, you saved my day there :)

@isnifer thank you! adding a trailing slash fixed things for me.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sudhishsasi picture sudhishsasi  Â·  3Comments

Solitaryo picture Solitaryo  Â·  8Comments

Jarzka picture Jarzka  Â·  4Comments

jevakallio picture jevakallio  Â·  5Comments

lequangnguyenqn picture lequangnguyenqn  Â·  5Comments