使用 Google 登录的 Expo 应用程序不会重定向到应用程序

问题描述

我的 Google 登录有问题,我目前正在使用 EXPO 应用程序我希望不惜一切代价不退出/选择退出 Expo,问题是当我点击按钮在我的应用程序中使用 Google 登录时,它确实会将我带到浏览器中的登录页面,但是一旦我输入了我的 Google 凭据,它就会进入 Google.com 页面。>

我查看了很多帖子,但仍然无法让它返回应用程序。

我的应用程序登录代码是:

//import de Google en Expo
import * as Google from 'expo-google-app-auth';
import * as AppAuth from 'expo-app-auth';

export const googleLogin = () => {
    console.log('***Entro en Google***');
    return async dispatch => {
        try {
            const result = await Google.logInAsync({
              androidClientId: '***my ID Censored***',scopes: ['profile','email'],behavior: 'web',redirectUrl: `${AppAuth.OAuthRedirect}:/oauthredirect`
            });
            console.log('***Hizo Consulta***');
            if (result.type === 'success') {
              console.log(result.accesstoken);
            } else {
              return { cancelled: true };
            }
          } catch (e) {
            return { error: true };
          }
    }
};

我检查了很多帖子,问题是重定向 URL,我尝试设置 4 个选项:

  1. ${AppAuth.OAuthRedirect}:/oauthredirect
  2. ${AppAuth.OAuthRedirect}:/oauthredirect/google
  3. 'host.exp.exponent:/oauth2redirect/google'
  4. 'host.exp.exponent:/oauth2redirect/'

他们都没有工作,我做了 host.exp.exponent 的最后 2 个,因为这是 Expo 在他们的文档中使用的 Bundle Identifier:

https://docs.expo.io/versions/latest/sdk/google/

创建 Android OAuth 客户端 ID

  1. 选择“Android 应用程序”作为应用程序类型。给它一个名字 如果您愿意(可能是“Android 开发”)。
  2. 运行 openssl rand -base64 32 | openssl sha1 -c 在你的终端中,它会输出一个字符串 看起来像 A1:B2:C3 但更长。将输出复制到剪贴板。 将上一步的输出粘贴到 “签名证书指纹”文本字段。
  3. 使用 host.exp.exponent 作为“包名”。 4.点击“创建”
  4. 您现在将看到一个带有客户 ID 的模式。
  5. 客户端 ID 用于 Google.loginAsync 的 androidClientId 选项(请参阅下面的代码示例)。

我就是这样做的,现在它总是卡在 google.com 页面中,有什么想法或建议吗?

亲切的问候

解决方法

在 app.json 中, 包名全部用小写字母,如 com.app.cloneapp