Auth0 React Native - Safari无法打开页面,因为地址无效

时间:2017-07-29 14:48:04

标签: react-native safari callback auth0 x-callback-url

我已经以正确的方式做到了这一点并且遇到了这样的problem

https://auth0.com/docs/quickstart/native/react-native/00-login

enter image description here

1 个答案:

答案 0 :(得分:4)

原生配置

Auth0需要处理托管登录身份验证的回调。

的Android

在文件android / app / src / main / AndroidManifest.xml中,您必须确保应用程序的主要活动的launchMode值为singleTask,并且它具有以下意图过滤器。

 <activity
  android:name=".MainActivity"
  android:label="@string/app_name"
  android:launchMode="singleTask"
  android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
  android:windowSoftInputMode="adjustResize">
  <intent-filter>
      <action android:name="android.intent.action.MAIN" />
      <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
  <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:host="yakupad.eu.auth0.com"
        android:pathPrefix="/android/${applicationId}/callback"
        android:scheme="${applicationId}" />
   </intent-filter>
  </activity>

的iOS

在文件ios // AppDelegate.m中添加以下内容:

 #import <React/RCTLinkingManager.h>

  - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url
   sourceApplication:(NSString *)sourceApplication annotation:    (id)annotation
   {
      return [RCTLinkingManager application:application openURL:url
                        sourceApplication:sourceApplication       annotation:annotation];
  }

接下来,您需要使用应用程序的包标识符添加URLScheme。

检查info.plist以查找现有的捆绑包标识符,例如

 <key>CFBundleIdentifier</key>
 <string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier).    </string>

然后,您可以通过添加以下代码段来注册标识符:

 <key>CFBundleURLTypes</key>
 <array>
    <dict>
       <key>CFBundleTypeRole</key>
       <string>None</string>
       <key>CFBundleURLName</key>
       <string>auth0</string>
       <key>CFBundleURLSchemes</key>
       <array>
         <string>org.reactjs.native.example.$(PRODUCT_NAME:rfc1034identifier).   </string>
    </array>
</dict>