【问题标题】:Issues with Expo Auth Session implementationExpo Auth Session 实施的问题
【发布时间】:2020-09-08 08:28:51
【问题描述】:

我在实施 Expo Auth Session 时遇到问题。

我正在 Expo Auth Session 中尝试使用 Google Oauth 登录,如下所述:https://docs.expo.io/guides/authentication/#google

WebBrowser.maybeCompleteAuthSession();

const GoogleButton = () => {
  // Endpoint
  const discovery = useAutoDiscovery('https://accounts.google.com');

  // Request
  const [request, response, promptAsync] = useAuthRequest(
    {
      clientId: 'MYID',
      scopes: ['email', 'profile'],
      // For usage in managed apps using the proxy
      redirectUri: makeRedirectUri({
        // For usage in bare and standalone
        native: 'com.googleusercontent.apps.MYID://redirect',
        useProxy: true,
      }),
    },
    discovery,
  );

  console.log(request);
  console.log(response);

  return (
    <Button
      onPress={promptAsync}
      icon={GoogleIcon}
    />
  );
};

浏览器打开,我可以用谷歌成功登录,但是当我被重定向到应用程序时,响应解析为Object { "type": "dismiss", }

我还尝试使用不同的 oauth 服务来实现 oauth:

WebBrowser.maybeCompleteAuthSession();

const HiveButton = () => {
  // Endpoint
  const discovery = {
    authorizationEndpoint:
      'https://hivesigner.com/login-request/my.app',
  };

  // Request
  const [request, response, promptAsync] = useAuthRequest(
    {
      scopes: ['posting'],
      // For usage in managed apps using the proxy
      redirectUri: makeRedirectUri({
        useProxy: true,
      }),
    },
    discovery,
  );

  console.log(request);
  console.log(response);

  return (
    <Button
      onPress={promptAsync}
      icon={HiveIcon}
    />
  );
};

浏览器打开,我可以成功登录,但我没有被重定向到应用程序,而是收到“尝试完成登录时出错。请关闭此屏幕以返回应用程序。”在 auth.expo.io/@me/myapp 上,即使参数代码具有我想要传递给我的应用程序的正确登录令牌。

【问题讨论】:

    标签: react-native oauth expo


    【解决方案1】:

    试试这个:

    -登录您的展会帐户: 在命令行类型上:

    expo login
    ##then your account credencials##
    

    然后重新启动您的 expo 实例:

    expo start
    

    一切正常

    【讨论】:

      【解决方案2】:

      我现在通过使用 AuthSession.startAsync 解决了第二个问题:

       const handleLogin = async () => {
          const redirectUrl = AuthSession.getRedirectUrl({ useProxy: true });
          const response = await AuthSession.startAsync({
            authUrl: `https://hivesigner.com/login-request/my.app?redirect_uri=${redirectUrl}&scope=posting`,
          });
      console.log(response)
      }
      

      我使用expo-google-sign-in 实现而不是使用 AuthSession 进行 Google 登录

      【讨论】:

        【解决方案3】:

        我有完全相同的问题。我也在世博论坛上发帖,并试图联系开发人员,但没有人回复我。我认为它已经被最近的变化打破了。如果您查看重定向 URL,它应该还有两个查询参数,一个用于身份验证 URL,一个用于返回 URL

        【讨论】:

          猜你喜欢
          • 2022-07-17
          • 1970-01-01
          • 2021-07-02
          • 2022-08-10
          • 2022-10-18
          • 2018-07-31
          • 2022-12-03
          • 2020-04-16
          • 2013-09-16
          相关资源
          最近更新 更多