Blake
Blake

Reputation: 299

Handle redirects with OAuth 2.0?

What is a good way to handle redirects in React Native with OAuth? There are external APIs I need to call, so I’ve registered my app, but I’m unclear what the redirect URI should be. For a web app, it would make sense how to handle this, but I’m not sure with React Native.

Upvotes: 1

Views: 1664

Answers (1)

Toby Flemming
Toby Flemming

Reputation: 519

What you need to do in React Native is setup your application for deep linking. A deep link is a way for another application or in this case your browser/WebView to say "Hey! I'd like to pass this information back to a native app".

Setup:

  1. Setup a url scheme in Xcode. This will allow you to redirect to url's formatted something like this myApp://oauthLogin
  2. Setup Linking

From there you should be able to create an event listener for the Redirect URI that you pass to the oauth service, in this case your deep link.

componentDidMount() {
  Linking.addEventListener('url', (url) => {
    console.log(url);
    // => myApp://oauthLogin?authCode=abc123
  });
}

You will have to add extra code the make sure the url is in the correct format but i hope that gets you closer!

Upvotes: 2

Related Questions