React-native-auth0: Authentication always returning `User cancelled the auth`

Created on 11 Oct 2017  路  10Comments  路  Source: auth0/react-native-auth0

Hi,

I'm currently working on an Instagram auth flow and the process always returns User cancelled the auth.

Another issue I've noticed is after authentication, the browser doesn't close; my app runs withing the browser.

  <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="mytestapp.auth0.com"
       android:pathPrefix="/android/${applicationId}/callback"
       android:scheme="${applicationId}" />
  </intent-filter>
  _handleInstagramAuth = () => {
    const auth0 = new Auth0({
      domain: 'mytestapp.auth0.com',
      clientId: 'xxxxxxxxxxxxx',
    });
    auth0.webAuth
      .authorize({
        scope: 'openid profile',
        audience: 'https://mytestapp.auth0.com/userinfo',
      })
      .then(
        credentials => debug('credentials', credentials)
      )
      .catch(error => debug('err', error));
  };

Libraries:
"react-native-auth0": "^1.2.1",
"react-native": "0.48.4",

Most helpful comment

@cocojoe If you open Android instructions from react-native-branch module: https://github.com/BranchMetrics/react-native-branch-deep-linking#android-setup

then you will find that they ask you to override onNewIntent method in MainActivity like this:

    @Override
    public void onNewIntent(Intent intent) {
        setIntent(intent);
    }

Because this method does not call super.onNewIntent the callback from Auth0's signup in webview/browser is not received back by Auth0.
This fixes the situation:

    @Override
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
    }

All 10 comments

Hi @ricbermo it would be great if you could provide additional information.

  1. Is this a new issue that has only appeared in 1.2.1 or this has never worked for you/first time you tried?
  2. Have you tried the sample project https://github.com/auth0-samples/auth0-react-native-sample
    If so, does it work? or you can reproduce the issue in the sample?

Thank you

Hi, I tried my app with version 1.1.0 and the issue remains. I cannot reproduce it with the sample project. I'll keep working on this and will update my finding. If you could provide me with something that could lead me to solve the issue I'd really appreciate it. Thank you

Hi @ricbermo, if the snippet works fine in the sample then the issue points to possible configuration of your project or something else you are doing. For example it could be something like missing the android:launchMode="singleTask" in your AndroidMainfest. I suggest having another read of https://auth0.com/docs/quickstart/native/react-native

If you can replicate your issue in the sample project then I can take a look at it.
Thx

And it was it; I was missing android:launchMode="singleTask". It's working with both versions 1.1.0 used in the example repo and with current 1.2.1. Thanks you so much @cocojoe

I have the same issue but android:launchMode="singleTask" is properly set. My best guess is that it conflicts with another package - for example I use Branch module which also uses URI scheme (its own) for callback. Is there any way I can debug where and why callback does not produce result?

@matejukmar Could you find a solution yet? I encountered the same problem.

@benseitz I did found a problem. When I was implementing Branch module I followed their example, where they override onNewIntent method in MainActivity without calling super.onNewIntent(intent) <- I had to add this line and then it started working.

@matejukmar Thank you so much! This solved my problem after countless hours of useless debugging! :1st_place_medal:

@matejukmar @benseitz can you walk me through your use case please so I can improve the documentation?

@cocojoe If you open Android instructions from react-native-branch module: https://github.com/BranchMetrics/react-native-branch-deep-linking#android-setup

then you will find that they ask you to override onNewIntent method in MainActivity like this:

    @Override
    public void onNewIntent(Intent intent) {
        setIntent(intent);
    }

Because this method does not call super.onNewIntent the callback from Auth0's signup in webview/browser is not received back by Auth0.
This fixes the situation:

    @Override
    public void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        setIntent(intent);
    }
Was this page helpful?
0 / 5 - 0 ratings

Related issues

jhazucha picture jhazucha  路  9Comments

pcurc picture pcurc  路  7Comments

a-jumping425 picture a-jumping425  路  5Comments

datvtwkm picture datvtwkm  路  3Comments

Abdisalan picture Abdisalan  路  5Comments