Auth0 callback URL with Capacitor native app?

Hi there,

I hope someone can help. I’m struggling to find any information about what the callback URL would be for a native app deployed using Capacitor.

I’ve seen some discussion about Ionic using ionic://, but we’re not using Capacitor with that.

I found one post that said to use capacitor://… but that never triggers going back to the app.

There’s a login “popup” option, but that doesn’t show the popup in the app

I’m still testing using the Android Simulator, so not sure if that’s part of the issue?

Has anyone managed to deploy a Capacitor / auth0 app without Ionic and get the redirect to work?

I’m using the auth0 SPA JS library.

Hope you can help!

Martin

I’m working on a similar thing, so I can share with you my solution.

But first, check out https://capacitorjs.com/docs/apis/app for more detail.

To use a custom URL scheme on android,

  1. In android/app/src/main/AndroidManifest.xml, inside the activity section, add the following:
<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="@string/custom_url_scheme" />
</intent-filter>
  1. Then in android/app/src/main/res/values/strings.xml, change the value of custom_url_scheme to your custom scheme.

  2. Finally in android/app/src/main/res/xml/config.xml, add the following at root so that only one instance of your app will be ever be launched and therefore after authentication the callback will always be delivered to the right app.

<preference name="AndroidLaunchMode" value="singleTask" />
1 Like

Thanks @alvis !

A combination of what you wrote and these docs to help get the right callback URL helped: Auth0 Ionic & Capacitor (React) SDK Quickstarts: Login

This was my callback URL:
[APP_ID]://[AUTH0_TENANT].eu.auth0.com/capacitor/[APP_ID]/callback

Where the APP_ID is usually the website domain backwards.

Then using your code where the custom_url_scheme is the website domain (not backwards) to allow the auth0 redirect / callback to open in Capacitor.

2 Likes

Teamwork makes the dreamwork!