Auth0 Home Blog Docs

Override redirect_uri from Mobile Application for Universal Login

Hello, we’re using Universal Login to centralize the authentication from our website and from our mobile applications.

We need to add some parameters to the redirect_uri. From the website we don’t have problems, we construct the authorize URL by embedding it in an href, and by adding some parameters as querystring; something like:

https://tenant.auth0.com/authorize?client_id=1234567&response_type=code&connection=db-connection&scope=openid email profile&redirect_uri=http://mywebsite.com/a0callback/?primary_domain=domain&primary_service=service

This pass the flow to the script inside the Universal Login Hosted Page in Auth0.

From the iOS mobile App we can override the redirect_uri by setting it as extraParam:

Auth0.webAuth()
	 .scope("openid profile")
	 .audience("https://" + clientInfo.domain + "/userinfo")
     .parameters([ "redirect_uri":"auth0.samples.Auth0Sample://tenant.auth0.com/ios/auth0.samples.Auth0Sample/callback?primary_domain=domain&primary_service=service"])
     .start {…}

By doing this when we debug the Auth0 WebView we see that the our redirect_uri overrides the callbackURL and we can manipulate the primary_domain value from the callbackUrl querystring.

Now, the problem is with the Android app; if we do the same in Android, setting the redirect_uri does not override the callbackUrl or the redirect_uri.

Map<String, Object> parameters = new HashMap<>();
parameters.put("redirect_uri","demo://tenant.auth0.com/android/com.auth0.samples/callback?primary_domain=domain&primary_service=service");
WebAuthProvider.init(auth0)
        .withScope("openid profile")
        .withScheme("demo")
        .withConnection("db-connection")
        .withParameters(parameters)
        .withAudience(String.format("https://%s/userinfo", getString(R.string.com_auth0_domain)))
        .start(MainActivity.this, new AuthCallback() {…}

Even if we use redirect_uri or callbackUrl key, the result is a callbackUrl without the parameters “?primary_domain=domain&primary_service=service

PS: we can’t pass primary_domain, primary_service as extraParams, we need that remains in the URL as querystring parmeters.

Any advice will be great.

Thanks!