React native 为什么不返回应用程序响应本机OAuth

React native 为什么不返回应用程序响应本机OAuth,react-native,oauth-2.0,React Native,Oauth 2.0,我正在尝试使用reat native auth包进行授权。当我更改值时​​在配置中,例如:clientId或redirect\u url,执行授权操作的站点会返回无效的客户端id或无效的redirect\u url错误。但是,当我尝试使用正确的值登录时,在输入登录过程的用户名和密码后,浏览器只是在等待。它只是在等待。我想知道我的交易是否有问题? 我认为问题是由android emulator引起的,以下是我的代码: export default class App extends Compone

我正在尝试使用reat native auth包进行授权。当我更改值时​​在配置中,例如:clientId或redirect\u url,执行授权操作的站点会返回无效的客户端id或无效的redirect\u url错误。但是,当我尝试使用正确的值登录时,在输入登录过程的用户名和密码后,浏览器只是在等待。它只是在等待。我想知道我的交易是否有问题? 我认为问题是由android emulator引起的,以下是我的代码:

export default class App extends Component {
  login = async () => {
    try {
      const result = await authorize(config);
    } catch (error) {
      console.log(error)
    }
  };
  render() {
    this.login();
    return (
      <View>
        <Text>asdasd</Text>
      </View>
    );
  }
}

我认为您在这里需要的主要功能是故障排除:

  • 使用诸如Fiddler/Charles Proxy之类的工具捕获OAuth消息
  • 验证授权响应是否按预期返回到应用程序
  • 使用您的配置设置获取另一个AppAuth示例
可能的白屏原因

  • 一个原因是在重定向过程中没有用户手势,尽管这往往是间歇性的,而您的问题似乎是永久性的
  • 另一种情况是,在清单文件中未正确配置net.openid.appauth.redirecturireceiveActivity以获取授权重定向响应
矿山资源

让Android AppAuth可靠地工作是一件棘手的事情,我花了一些时间。如果有帮助的话,我有一些资源可以给你一些想法和比较。但是,它们没有以React Native进行编码,因此可能不是您问题的完整答案:

  • 开始工作
  • 开始工作
  android {
    compileSdkVersion rootProject.ext.compileSdkVersion

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        applicationId "com.oauth"
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionName "1.0"
        manifestPlaceholders = [
            appAuthRedirectScheme: 'androidapp://foo'
        ]
    }