Reactjs AWS Cognito不适用于IE 11,但适用于所有其他浏览器

Reactjs AWS Cognito不适用于IE 11,但适用于所有其他浏览器,reactjs,internet-explorer,safari,amazon-cognito,saml,Reactjs,Internet Explorer,Safari,Amazon Cognito,Saml,因此,我尝试使用cognito在react应用程序中管理身份验证,身份提供者是SAML。这在Chrome和Firefox中运行得非常顺利,但在IE11中却不行。以下是我设置身份验证的步骤: import { Component } from 'react'; import { connect } from 'react-redux'; import { CognitoAuth } from 'amazon-cognito-auth-js'; import { signIn, signOutSuc

因此,我尝试使用cognito在react应用程序中管理身份验证,身份提供者是SAML。这在Chrome和Firefox中运行得非常顺利,但在IE11中却不行。以下是我设置身份验证的步骤:

import { Component } from 'react';
import { connect } from 'react-redux';
import { CognitoAuth } from 'amazon-cognito-auth-js';
import { signIn, signOutSuccess } from '../store/auth';
import { setupAxios } from '../axios';

import {
  AWS_COGNITO_CLIENT_ID,
  AWS_COGNITO_USER_POOL_ID,
  AWS_COGNITO_REDIRECT_SIGN_IN,
  AWS_COGNITO_REDIRECT_SIGN_OUT,
  AWS_COGNITO_APP_WEB_DOMAIN
} from '../env';

const cognitoSetup = props => {
//as per documentation
  const authData = {
    ClientId: AWS_COGNITO_CLIENT_ID,
    TokenScopesArray: ['email', 'openid', 'profile'],
    RedirectUriSignIn: AWS_COGNITO_REDIRECT_SIGN_IN,
    RedirectUriSignOut: AWS_COGNITO_REDIRECT_SIGN_OUT,
    AppWebDomain: AWS_COGNITO_APP_WEB_DOMAIN,
    IdentityProvider: 'SAML',
    UserPoolId: AWS_COGNITO_USER_POOL_ID
  };

  const auth = new CognitoAuth(authData);
  auth.useCodeGrantFlow(); //getting the refresh token

  auth.userhandler = {
    onSuccess: result => {
      const { profile, name, family_name, email } = result.idToken.payload;
      //passes role to store for use in the rest of the app
      const username = result.idToken.payload.identities[0].userId;
      const fullName = `${name} ${family_name}`;
      props.signIn({ username, profile, fullName, email });
    },
    onFailure: function(err) {
      console.error(err);
      throw err;
    }
  };
  return auth;
};


export class AuthService extends Component {
  constructor(props) {
    super(props);
    this.authService = cognitoSetup(this.props);
//passes the auth to axios to check for token on request
    setupAxios(this.authService);
  }

  componentDidMount() {
    const curUrl = window.location.href;
    if (curUrl.includes('?code=')) {
      this.authService.parseCognitoWebResponse(curUrl);
    } else if (!curUrl.includes('?error')) {
      this.authService.getSession();
    }
  }

  signOut = async () => {
    await this.authService.signOut();
  };

  async componentDidUpdate(prevProps) {

    if (prevProps.shouldSignOut !== this.props.shouldSignOut) {
      if (this.props.shouldSignOut) {
        await this.signOut();
        this.props.signOutSuccess();
      }
    }
  }
//render nothing 
  render() {
    return null;
  }
}

const mapState = state => ({
  username: state.auth.username,
  signedIn: state.auth.signedIn,
  shouldSignOut: state.auth.shouldSignOut
});

const mapDispatch = dispatch => ({
  signIn: (username, profile) => dispatch(signIn(username, profile)),
  signOutSuccess: () => dispatch(signOutSuccess())
});

export default connect(mapState, mapDispatch)(AuthService);

此AuthService.js在加载应用程序时呈现。但是,在IE11中加载时,出现了一个错误
var jsonDataObject=JSON.parse(jsonData)无效字符

我不知道为什么会这样。我已经调查并得出结论,这是在amazon cognito auth js包中进行的。我的印象是这个包是由亚马逊制作的,所以我相信这个包没有错,但我看不到其他人有这个问题。有人有什么建议吗


编辑:我有一个polyfill,我看到你在IE的代码中使用了箭头函数。你可以用它和任何其他ES6语法编译成ES5。例如,编译:

const cognitoSetup = props => {
  ...
}
致:


此外,您是否在
src/index.js
的第一行导入了
react-app-polyfill
?这是react应用程序在IE 11中运行所必需的。您可以参考中的答案了解详细步骤。

我感谢您的建议,但是我有一个polyfill,并且在整个应用程序中使用箭头函数。这不是问题所在,引发的问题是一个Json.parse()错误,该错误声称存在无效字符。该错误指向哪一行?如何使用
JSON.parse()
函数?在您的问题中,我找不到有关此函数的代码段。你能提供这个问题吗?我的代码库中没有使用JSON.parse(),我相信它是在
this.authService.parseCognitoWebResponse(curUrl)中使用的JSON.parse()
不在函数
parseCognitoWebResponse()
中。该错误是否可能发生在代码的其他部分?此外,jsonData传递到什么地方?错误通常发生在json数据格式无效时。确切地说,我也查看了源代码,它似乎是在onSuccessExchangeForToken()和onSuccessRefreshToken()中调用的。我不完全确定是什么导致了这个问题,但是IE说jsonData是未定义的。但实际上,这在其他浏览器中都能正常工作,所以我对文字感到困惑,有什么想法吗?
var cognitoSetup = function cognitoSetup(props) {
  ...
}