Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calling Token Endpoint Twice #3642

Closed
ghariosk opened this issue Jul 13, 2019 · 5 comments
Closed

Calling Token Endpoint Twice #3642

ghariosk opened this issue Jul 13, 2019 · 5 comments
Labels
Auth Related to Auth components/category React Native React Native related issue

Comments

@ghariosk
Copy link

ghariosk commented Jul 13, 2019

Describe the bug
Using react-native I am wrapping my App component with with0Auth exactly like the example provided in the documentation. I am getting an error of invalid request. Upon inspecting the debug log it seems the token endpoint is being called twice, the first time with the code verifier and the second time without and the second time is is returning invalid request. I am using expo. I know I could use Implicit grant and response_type = token but aws strongly recommends against it on mobile.
Note:
I am able to get the response with postman using the first token endpoint call.

To Reproduce
Steps to reproduce the behavior:

  • configure aws amplify with social provider.
  • copy my code
  • Sign in with facebook using button
  • inspect the the debug log

Expected behavior
Token Id and refresh token being returned

Screenshots

Screenshot 2019-07-13 10 57 21

Screenshot 2019-07-13 10 57 35

Smartphone (please complete the following information):

  • Device: iPhone 6
  • OS: iOS 12.3.1
  • Browser: Safari
  • Version [e.g. 22]

Additional context
Add any other context about the problem here.

Sample code

import { StyleSheet, Text, ScrollView, SafeAreaView, StatusBar, Button, Image } from 'react-native';

import { withOAuth } from "aws-amplify-react-native";
import { default as awsConfig } from "./aws-exports";
import { CognitoUserPool, CognitoUserAttribute, CognitoUser } from 'amazon-cognito-identity-js';

Amplify.configure(awsConfig);




class App extends React.Component {
  constructor(props) {
    super(props);
    
    // let the Hub module listen on Auth events
    // Hub.listen('auth', (data) => {
    //     switch (data.payload.event) {
    //         case 'signIn':
    //             this.setState({authState: 'signedIn'});
    //             this.setState({authData: data.payload.data});
    //             console.log('test')
    //             console.log(JSON.stringify(this.state.authData))
    //             break;
    //         case 'signIn_failure':
    //             this.setState({authState: 'signIn'});
    //             this.setState({authData: null});
    //             this.setState({authError: data.payload.data});
    //             console.log('test2')
    //             break;
    //         default:
    //             break;
    //     }
    // });
    this.state = {
      authState: 'loading',
      authData: null,
      authError: null
    }
  }


 



  render() {
    const {
      oAuthUser: user,
      oAuthError: error,
      hostedUISignIn,
      facebookSignIn,
      googleSignIn,
      amazonSignIn,
      customProviderSignIn,
      signOut,
    } = this.props;



    return (
      <SafeAreaView style={styles.safeArea}>

      <Image style={{width:50, height:50}} source={{uri: "https://platform-lookaside.fbsbx.com/platform/profilepic/?asid=10162093254815441&height=250&width=250&ext=1565516276&hash=AeTbiMwfzv6SHnkK"}}/>
     {user && <Button title="Sign Out" onPress={signOut} icon='logout' />}
        <ScrollView contentContainerStyle={styles.scrollViewContainer}>
        <Text>{JSON.stringify({ user, error, }, null, 2)}</Text>
          
          {!user && <React.Fragment>
            {/* Go to the Cognito Hosted UI */}
            <Button title="Cognito" onPress={hostedUISignIn} />
           

            {/* Go directly to a configured identity provider */}
            <Button title="Facebook" onPress={facebookSignIn} />
            <Button title="Google" onPress={googleSignIn}  />
            <Button title="Amazon" onPress={amazonSignIn} />
            

            {/* e.g. for OIDC providers */}
            <Button title="Yahoo" onPress={() => customProviderSignIn('Yahoo')} />
          </React.Fragment>}
        </ScrollView>
      </SafeAreaView>
    );
  }
}

const styles = StyleSheet.create({
  safeArea: {
    flexGrow: 1,
    paddingTop: StatusBar.currentHeight,
    backgroundColor: '#FFFFFF',
  },
  scrollViewContainer: {
    flexGrow: 1,
    alignItems: 'center',
    justifyContent: 'center',
  }
});

window.LOG_LEVEL = 'DEBUG'

export default withOAuth(App);

my aws-config :

// WARNING: DO NOT EDIT. This file is automatically generated by AWS Amplify. It will be overwritten.

const awsmobile = {
    "aws_project_region": "eu-central-1",
    "aws_cognito_identity_pool_id": "xxx-aadc-2deefc909628",
    "aws_cognito_region": "eu-central-1",
    "aws_user_pools_id": "eu-central-1_xxxx",
    "aws_user_pools_web_client_id": "xxxx",
    "oauth": {
        "domain": "userpool2-dev.auth.eu-central-1.amazoncognito.com",
        "scope": [
            "phone",
            "email",
            "openid",
            "profile",
            "aws.cognito.signin.user.admin"
        ],
        "redirectSignIn": "exp://48-6yaxxxx.userpool.exp.direct:80",
        "redirectSignOut": "exp://48-6yaxxxx.userpool.exp.direct:80",
        "responseType": "code"
    },
    "federationTarget": "COGNITO_USER_POOLS"
};


export default awsmobile;

You can turn on the debug mode to provide more info for us by setting window.LOG_LEVEL = 'DEBUG'; in your app.

@haverchuck
Copy link
Contributor

@ghariosk - We merged a PR last week into our unstable branch which I think might address this issue. Could you try it with npm i aws-amplify@unstable?

@haverchuck haverchuck added React Native React Native related issue Auth Related to Auth components/category pending-close-response-required labels Jul 15, 2019
@ghariosk
Copy link
Author

Just tried it and works perfectly now! Thanks 👍

@martrik
Copy link

martrik commented Nov 27, 2019

I'm on version 2.1.0 and still experiencing this issue. I'm using the withOAuth HOC from aws-amplify-react in web React though.

@PeterLAxakon
Copy link

I'm also having this problem endpoint seems to be called twice. Following examples from here. https://docs.amplify.aws/ui/auth/authenticator/q/framework/react#hiding-form-fields

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 30, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Auth Related to Auth components/category React Native React Native related issue
Projects
None yet
Development

No branches or pull requests

4 participants