Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google SignIn In Cognito Using Custom Login Form

Tags:

Currently, I am trying to implement Social Login for my web Application using Cognito Aws Service. But I don't want to redirect the user to Cognito Hosted UI for Social Login.

So I use react-google-login for the Google Login and I am getting the callback access token too

<GoogleLogin
   clientId="xxxxxxxxxxxxxx.apps.googleusercontent.com"
   buttonText="Login"
   onSuccess={this.responseGoogle}
   onFailure={this.responseGoogleFailure}
   cookiePolicy={'single_host_origin'}
/>


responseGoogle = async (response) => {
  console.log("response..........", response);
  const user = {
    name: response.profileObj.name,
    email: response.profileObj.email
  };

  let expires_at = 3600 * 1000 + new Date().getTime()

  Auth.federatedSignIn('google', { token: response.tokenId, expires_at }, user).then(credentials => {
     console.log(credentials);
  });
}

The above code gives the Cognito session values but that doesn't create a user in the user pool.

I have search a lot but didn't find any solutions. I have already referred this below links it refers to my problem. Basically I don't want to use hosted UI for the SocialLogin.

Thank In advance

https://github.com/aws-amplify/amplify-js/issues/1316

https://github.com/aws-amplify/amplify-js/issues/3875

like image 959
Narendra Chouhan Avatar asked Nov 09 '19 10:11

Narendra Chouhan


People also ask

How do I customize my AWS Cognito login page?

Sign in to the Amazon Cognito console . In the navigation pane, choose User Pools, and choose the user pool you want to edit. Choose the App integration tab. To customize UI settings for all app clients, locate Hosted UI customization and select Edit.

How do I get Google using Cognito?

You can also use a keyboard shortcut to open an Incognito window: Windows, Linux, or Chrome OS: Press Ctrl + Shift + n. Mac: Press ⌘ + Shift + n.

How do I create a Cognito login?

Go to AWS Cognito service and click “Manage Identity Pools”. 2. Enter “Identity pool name”, expand the “Authentication providers” section and select “Cognito” tab. This is where the Cognito authentication provider will be registered with the Identity pool.


1 Answers

It is possible to open the link directly to the Google login page without showing the hosted ui but still have the authentication go through Cognito, you basically link directly to the url which is opened when you select the Google button in the Cognito hosted ui i.e.

https://<YOUR_DOMAIN>.auth.<REGION>.amazoncognito.com/oauth2/authorize?identity_provider=Google&redirect_uri=<REDIRECT_URI>&response_type=TOKEN&client_id=<CLIENT_ID>&scope=openid

You will end up back at your redirect uri after the auth and the user will have been created/authenticated.

like image 172
James Walsh Avatar answered Oct 02 '22 19:10

James Walsh