Redirecting Back to App After User Accepts Permissions Oauth2

送分小仙女□ 提交于 2019-12-05 21:51:08

Since this was a very hard problem to overcome and this question has not received a lot of attention, I suspect someone else in the future would appreciate an example of how I overcame this.

Problem

Handling the redirect after a user accepts permissions using the Lyft API 3 leg Oauth flow.

Solution

Example Solution Repo Here

In order to handle this I used Deep Linking which is supported by React Native. I also had to setup links in the IOS and Android applications. These links needed to be the same as the redirect URL in the Lyft Developers Page so the app could be opened back up when the link was fired off on the mobile device with the application on it. This can be done as followed,

  1. Setup Deep Linking. Instructions on how to add Linking to your app can be found here.

  2. The URLS are not explained at that React Native Link. Here are the resources for the Deep Links for each OS. Apple / Android

  3. You will have to add a redirect URL to your Lyft App in the Developers page. This URL will be finessed into the native app settings for each OS, (IOS & ANDROID). You will make that the redirect URL in the Lyft Developer App Page here.

Code Example

Android

AndroidManifest.xml

<intent-filter android:label="lyft-app-authorize">
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="http"
        android:host="lyft-app"
        android:pathPrefix="/authorize" />
</intent-filter>
<intent-filter android:label="lyft-app-authorize">
  <action android:name="android.intent.action.VIEW" />
  <category android:name="android.intent.category.DEFAULT" />
  <category android:name="android.intent.category.BROWSABLE" />
  <data android:scheme="lyft-app"
        android:host="authorize" />
 </intent-filter>

IOS

info.plist

<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>lyft-app</string>
    </array>
  </dict>
</array>

AppDelegate.swift

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
            options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
  return [RCTLinkingManager application:application openURL:url options:options];
}

- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
  return [RCTLinkingManager application:application
                   continueUserActivity:userActivity
                     restorationHandler:restorationHandler];
}

Lyft Developer App Page

App Management Page

React Native

Load URL / Handle Redirect

  componentDidMount() {
        Linking.openURL(url);
        Linking.addEventListener('url', (responseUrl) => {
          console.log(responseUrl);
        });
      }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!