首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用自定义域的react本机-google-signin

使用自定义域的react本机-google-signin
EN

Stack Overflow用户
提问于 2019-09-25 07:37:10
回答 1查看 344关注 0票数 1

我有谷歌登录在一个网络和一个反应本地应用(android和ios)。

我可以在这两个平台上登录,但是令牌数据不同(因此应用程序的一个是无效的)

我看过医生,在不同的领域尝试过多个对角线,但没有成功

应用程序配置:

代码语言:javascript
复制
      // scopes: ['profile', 'email'], // it doesn't matter if commented or not
      // webClientId: '**********.apps.googleusercontent.com', //
      // offlineAccess: false, // if you want to access Google API on behalf of the user FROM YOUR SERVER
      // hostedDomain: 'https://securetoken.google.com/**********', // if I use this, (or other strings I tried, cant login
      // loginHint: '',
      forceConsentPrompt: true,
      accountName: '**********', // 
      // accountName: '**********:android:**********', // nothing happens
      iosClientId: '**********.apps.googleusercontent.com', // is different from the android one

web配置(带有防火墙):

代码语言:javascript
复制
      apiKey: "**********",
      authDomain: "**********.firebaseapp.com",
      databaseURL: "https://**********.firebaseio.com",
      projectId: "**********",
      storageBucket: "",
      2: "**********",
      appId: "**********:web:**********"

web令牌信息:

代码语言:javascript
复制
 {
    "iss": "https://securetoken.google.com/**********",
    "aud": "**********",
    "sub": "**********",
    "email": "**********@gmail.com",
    "email_verified": true,
    "name": "**********",
    "picture": "**********",
    "auth_time": 1568973313,
    "user_id": "**********",
    "sign_in_provider": "google.com",
    "iat": **********,
    "exp": **********,
    "firebase": {
      "identities": {
        "google.com": ["**********"],
        "email": ["**********@gmail.com"]
      }
    }
  }

应用程序令牌信息:

代码语言:javascript
复制
 {
    "iss": "https://accounts.google.com",
    "azp": "**********.apps.googleusercontent.com",
    "aud": "**********.apps.googleusercontent.com",
    "sub": "**********",
    "email": "**********@gmail.com",
    "email_verified": true,
    "name": "**********",
    "picture": **********",
    "given_name": "**********",
    "family_name": "**********",
    "locale": "es",
    "iat": **********,
    "exp": **********
  }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-09 09:24:09

我设法使用同样的防火墙(firebase.initializeApp(/params/))来解决这个问题,首先我使用react-native-google-signin进行登录,如果成功的话,使用firebase登录以获得正确的令牌:

代码语言:javascript
复制
// login with google, on web is unnecesary, to use native interface
const { user } = await GoogleSignin.signIn();
const googleTokens = await GoogleSignin.getTokens();

// login with firebase, to get the correct token
const credential = firebase.auth.GoogleAuthProvider.credential(googleTokens.idToken, googleTokens.accessToken);
const auth = firebase.auth();
await auth.signInWithCredential(credential);

// get firebase token and user email
const idToken = auth.currentUser && (await auth.currentUser.getIdToken(true));
const email = user && user.email;

// login into my back
if (idToken && email) googleLogIn(email, idToken);
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58093415

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档