React-native-auth0: Integration into existing Android Client - User canceled the auth error

Created on 6 Jan 2018  路  9Comments  路  Source: auth0/react-native-auth0

Hi,
I've integrated my react-native app including the react-native-auth0 library into an existing Android project following this tutorial https://facebook.github.io/react-native/docs/integration-with-existing-apps.html.

The integration worked almost perfectly. But when I try to login, the custom tab intent starts and after a short while I get redirected to my login screen and I get the following error
{"error": "a0.session.user_cancelled",
"error_description": "User cancelled the Auth"}.

When I check the auth0 dashboard at www.auth0.com , I can see that the login was actually successful. So there must be a redirection error. The callback URL is correct.

I followed the react-native-auth0 guide and applied launchMode="singleTask" to the respective activity etc.
Also I tried different versions of chromeTabs.

The thing is that the login part works perfectly in my stand-alone react-native project.
My instinct says that it has to do something with the gradle config. On the other hand I tried different versions, downgraded the project to 23.0.1 etc.

I'm using
react-native-auth0 1.2.1
react-native 0.50.3
and I don't know if it is important
react-native-router-flux 4.0.0-beta.24

My ReactActivity in the AndroidManifest.xml is configured as follows:

        <activity
            android:name=".alightversion.ReactCreateEventActivity"
            android:theme="@style/Theme.AppCompat.Light.NoActionBar"
            android:launchMode="singleTask"
            android:label="@string/app_name"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
            android:windowSoftInputMode="adjustResize"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <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:host="XXX" <!-- I hid the correct host for this post -->
                    android:pathPrefix="/android/${applicationId}/callback"
                    android:scheme="${applicationId}" />
            </intent-filter>
        </activity>

This is my build.gradle (Module: app)

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.android.application'

android {
    compileSdkVersion 25
    buildToolsVersion '26.0.2'

    defaultConfig {
        applicationId "org.bla.bla"
        minSdkVersion 16
        targetSdkVersion 25
        versionCode 1
        versionName "0.0.1"
        multiDexEnabled true

        testInstrumentationRunner 'android.support.test.runner.AndroidJUnitRunner'

        ndk {
            abiFilters "armeabi-v7a", "x86"
        }

        packagingOptions {
            exclude "lib/arm64-v8a/librealm-jni.so"
        }
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    configurations {
        all {
            exclude module: 'httpclient'
        }
    }

    packagingOptions {
        exclude 'META-INF/DEPENDENCIES'
        exclude 'META-INF/LICENSE'
        exclude 'META-INF/LICENSE.txt'
        exclude 'META-INF/license.txt'
        exclude 'META-INF/NOTICE'
        exclude 'META-INF/NOTICE.txt'
        exclude 'META-INF/notice.txt'
        exclude 'META-INF/ASL2.0'
    }
}
dependencies {
    compile project(':react-native-auth0')
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    }
    compile 'com.android.support:appcompat-v7:25.4.0'
    compile 'com.android.support:design:25.0.0'
    compile 'com.google.android.gms:play-services:10.2.1'
    compile 'com.google.android.gms:play-services-maps:10.2.1'
    compile 'com.google.code.gson:gson:2.7'
    compile 'org.apache.httpcomponents:httpclient:4.5'
    compile 'io.reactivex:rxandroid:0.24.0'
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.wdullaer:materialdatetimepicker:1.4.1'
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile 'com.github.bumptech.glide:glide:3.7.0'
    compile 'com.google.firebase:firebase-messaging:10.2.1'
    compile "de.halfbit:pinned-section-listview:1.0.0"
    compile "com.facebook.react:react-native:+"
}

This is my build.gradle (Project:android)

// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
    repositories {
        jcenter()
        maven {
            url 'https://maven.google.com/'
            name 'Google'
        }
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:3.0.1'
        classpath 'com.google.gms:google-services:3.1.0'

        // NOTE: Do not place your application dependencies here; they belong
        // in the individual module build.gradle files
    }
}

allprojects {
    repositories {
        jcenter()
        google()
        maven {  // All of React Native (JS, Android binaries) is installed from npm
            url "$rootDir/../node_modules/react-native/android"
        }
    }
}

Most helpful comment

Has anyone managed to get this working?

RNAuth0 1.3.0
RNNavigation 2.0.2538

Edit: Managed to get this working! I mistakenly had android:launchMode="singleTask" under <application> and not <activity>.

All 9 comments

I could fix the problem.
I had to add to the following code into my activity class:

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    mReactInstanceManager.onNewIntent(intent);
}

I am seeing this same issue. ~Would an improper Callback URL result in this? The instructions are a little confusing on what to use. I took this word for word:~

~{YOUR_APP_PACKAGE_NAME}://YOUR_AUTH0_DOMAIN/android/{YOUR_APP_PACKAGE_NAME}/callback~
~And didn't add an http or https identifier as I'm not sure where it's supposed to go?~

Edit: Disregard that, I just tried changing the Callback URL and realized it results in a totally separate error.

Final Edit: Realized that my android:launchMode="singleTask" was in the wrong header section. Looking at the Manifest pointed above, it looks like you don't have that issue. Sorry I couldn't be of more help.

@pythoneer I can confirm that PR #93 does not appear to be the fix for this case.

Is this still an issue?

I'm currently experiencing the same issue. I've got android:launchMode="singleTask" set on my manifest.

The callback URL seems to be triggering - i.e. it returns from the CustomTab. But it doesn't seem to be picking up the actual callback function and instead shows the same error as above
```
{"error": "a0.session.user_cancelled",
"error_description": "User cancelled the Auth"}

Following up - if I remove android:launchMode="singleTask" from the manifest, and use Linking.getInitialURL() I can see that the callback URL is being correctly triggered and returns the code parameter.

Has anyone managed to get this working?

RNAuth0 1.3.0
RNNavigation 2.0.2538

Edit: Managed to get this working! I mistakenly had android:launchMode="singleTask" under <application> and not <activity>.

@kevinranks did the same, ty!

Just FYI, redirection in android might not work when this SDK is used along the RN Navigation library. This is due to how the deep links work on react-native.

Was this page helpful?
0 / 5 - 0 ratings