What is the RedirectURL in react-native-app-auth - and how do I get back to my app?

Viewed 7821

I'm a noob in the world of React-Native development and am trying to work out how to configure FormidableLabs' react-native-app-auth plugin so that a user of our app can sign in to our Identity Server 4 implementation and then return to the app.

I can get to the sign-in form easily enough - but after signing in it goes to another Identity Server page in the browser rather than back to the app. I assume this is because of a wrong configuration, but I've searched the net far and wide for an answer that actually explains what the redirectUrl should actually point to - in all the examples it just points to io.identityserver.demo:/oauthredirect. Is it possible to redirect back to an app?

What I've also noticed is that the original request to the login page does not pass it a ReturnUrl - that parameter is null.

I feel I'm missing something obvious here, but I cannot think what it is.

Here's the relevant code from the app:

import {authorize} from 'react-native-app-auth';
...
const config = {
                    issuer: 'http://10.0.2.2:5000',
                    clientId: 'MyApp',
                    redirectUrl: '?? what goes here ??',
                    scopes: ['openid', 'profile', 'offline_access'],
                    serviceConfiguration: {
                        authorizationEndpoint: `http://10.0.2.2:5000/Account/Login`,
                        tokenEndpoint: `http://10.0.2.2:5000/connect/token`
                    }            
                }
                const result = await authorize(config);

The Identity Server is running on port 5000 (in localhost on my pc).

Can anyone point out what I'm doing wrong?

Thanks in advance!

2 Answers

You have 2 main choices for a redirect URI and the first option is simpler but a little less secure:

In order for the redirect to return to the app you need to register the scheme with the Android / iOS systems.

PRIVATE URI SCHEME

My write ups should enable you to quickly run the standard samples and get Private URI schemes working. You can then set similar Android / iOS settings in your ReactNative app:

CLAIMED HTTPS SCHEME

This is more effort but my blog also has Android / iOS samples that you can run and read about in case interested.

You are on the right track, once the user has logged into IdentityServer it will redirect back to redirectUrl.

I suggest you to read the docs as it has it explained with example code.

Related