错误:无效的登录令牌。使用AWS Amplify Auth.federatedSignIn()时,颁发者与providerName不匹配

时间:2018-09-03 05:48:44

标签: aws-amplify cognito

import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Linking , Button} from 'react-native';
import SafariView from 'react-native-safari-view';
import shittyQs from 'shitty-qs';

import Amplify, { Auth } from 'aws-amplify';
import aws_exports from './aws_exports';
Amplify.configure(aws_exports);


export default class App extends Component {



  componentDidMount() {
    const a =Linking.getInitialURL();
    console.log(a)
    Linking.addEventListener('url', this._handleOpenURL);
  }

  componentWillUnmount() {
    Linking.removeEventListener('url', this._handleOpenURL);
  }

  _handleOpenURL= (event) => {
    console.log(event.url);

    const [, query_string] = event.url.match(/\#(.*)/);
    const query = shittyQs(query_string)
    console.log('query.access_token', query.access_token)
    console.log('query.id_token', query.id_token)
    console.log('query.expires_in', query.expires_in)

    this.fedratedSigninMethod(query.id_token,  query.expires_in);
    if (Platform.OS === 'ios') {
      SafariView.dismiss();
    }
  }

  openLink = () => {
    const url = 'https://authapp123.auth.ap-south-1.amazoncognito.com/login?response_type=token&client_id=5i90872dee116qirrab1mbm6tm&redirect_uri=deeplinkapp://';
    if (Platform.OS === 'ios') {
        SafariView.show({
          url: url,
          fromBottom: true,
        });
      }
      else {
        Linking.openURL(url);
      }
  }


  fedratedSigninMethod = (id_token, expires_at) => {
    const user = {
      username: 'wdevon99@gmail.com',
      password: 'Devon@123456',
      attributes: {
          email: 'wdevon99@gmail.com'
      }
    }

    Auth.federatedSignIn(
      // Initiate federated sign-in with Google identity provider 
      'google',
      { 
          // the JWT token
          token: id_token, 
          // the expiration time
          expires_at 
      },
      // a user object
      user
    ).then((res) => {
        console.log('ressss = >' , res)
    }).catch((err)=>{
        console.log('err = > ' , err)
    });
  }

尝试注册时出现以下错误,错误:无效的登录令牌。使用AWS Amplify Auth.federatedSignIn()时,颁发者与providerName不匹配。以下是我用来测试此内容的react native项目的代码 1个 帮助:p'

尝试注册时出现以下错误,错误:无效的登录令牌。使用AWS Amplify Auth.federatedSignIn()时,颁发者与providerName不匹配。以下是我用来测试此内容的react native项目的代码 1个 帮助:p

0 个答案:

没有答案