如何使用 Strapi 和 React Native 处理 Google 身份验证

问题描述 投票:0回答:1

我正在尝试在我的 React Native 应用程序中实现 Google 身份验证,并希望将所有数据存储在 Strapi 中。 Strapi 确实提供了 Google 身份验证支持,但我认为这可以与 SPA 一起使用。请帮助我如何在 React Native 中开始使用它。

react-native google-oauth strapi
1个回答
0
投票

我找到了一种使用 firebase 的直切方法

  1. 设置/安装firebase应用程序,附带@react-native-firebase,只需按照安装步骤操作即可
  2. 安装@react-native-google-signin/google-signin
  3. 在 firebase 控制台中启用 google 身份验证并获取 Web 客户端 ID 和 Web 客户端密钥
  4. 分别将这2个添加到strapi googleprovider的Client ID和Client Secret中
  5. 现在,在登录页面的 React Native 应用程序中

import { GoogleSignin } from "@react-native-google-signin/google-signin";

GoogleSignin.configure({
  webClientId: "<web client ID>",
  forceCodeForRefreshToken: true,
  accountName: "",
});

const googleLogin = async () => {
  await GoogleSignin.signOut();
  await GoogleSignin.hasPlayServices();
  await GoogleSignin.signIn();
  const { accessToken } = await GoogleSignin.getTokens();
  const response = await Api.get(
    `${strapi_url}/api/auth/google/callback?access_token=${accessToken}`
  );
};

// response -> you will have the strapi signed-in user

一切就绪!

© www.soinside.com 2019 - 2024. All rights reserved.