首页 > 解决方案 > Android - Google OAuth 2 - 使用不同验证码的两次响应

问题描述

我在 Android 9 及更低版本上遇到了 Oauth Google 问题。

设置:

我开发了一个应用程序:

问题 :

我不确定问题出自 nativescript-oauth2 插件,可能是我的 android 应用程序配置或 Google Frame。

我使用 Facebook 和 Google 提供商开发了 OAuth 登录。对于 Facebook,没问题。

Facebook 使用网络视图浏览器,而 Google 使用本地视图浏览器。

对于谷歌,见下文:

更多细节: 我调试了应用程序和 nativescript-oauth2 插件。我看到带有等待消息的谷歌框架(在选择谷歌帐户后)向 Android 发送了 2 个事件,其中“代码”参数的值不同。当然,第一个代码已过期/撤销,Google 返回错误。

在 OAuth Google 文档中,这是第 4 步,它使用 2 个代码发送 2 个响应。

我的问题

为什么 Google Frame 浏览器会向我发送 2 个事件?

代码 :

这是我的 AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="__PACKAGE__"
    android:versionCode="1"
    android:versionName="1.0">

    <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"/>

    <application
        android:name="com.tns.NativeScriptApplication"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="com.tns.NativeScriptActivity"
            android:label="@string/title_activity_kimera"
            android:launchMode="singleTask"
            android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout|locale|uiMode"
            android:theme="@style/LaunchScreenTheme">

            <meta-data android:name="SET_THEME_ON_LAUNCH" android:resource="@style/AppTheme" />

            <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" />
                <!-- Custom URL Schemes -->
                <data android:path="/auth"
                      android:scheme="com.googleusercontent.apps.xxxxxxxx-yyyyyyyyyyyyyyyyyy"/>
            </intent-filter>
        </activity>
        <activity android:name="com.tns.ErrorReportActivity"/>

        <meta-data
                android:name="com.google.android.geo.API_KEY"
                android:value="xxxxxxxxxxxxxxxxx" />
    </application>

    <uses-sdk
            android:minSdkVersion="17"
            android:targetSdkVersion="__APILEVEL__"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"  />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
</manifest>

标签: androidgoogle-oauthnativescript

解决方案


推荐阅读