Cognito provided 2 different types of identity management solutions, User Pools and Federated Identities.
User pools are the default "users" management. You can set them up to login using username & password(default) / email address & password. When a user have registered (and probably verify their email), your application will get a Cognito user object when they signed in. You can extract their email, scope, and 3 JWT tokens (id, access, refresh) from the Cognito user object.
If you use User Pools, you can also have an option to signin using third party like google or facebook. However this is different from federated identities (explained below), just beware of that when googling 😃 . If you use third party in user pools, you will still get back a Cognito User object with the 3 JWT tokens(id, access, refresh). If you need their email (which you probably would because the username will be something like Googleuser_abc1234
), make sure to add an Attribute Mapping for email in the Cognito console.
The way User Pools social signin works (from my observation) is from a Hosted UI (AWS provided) or your own ui (like I did), it will go through Cognito and Cognito will redirect you to your social identity provider (can see the callback in the query params). After signing in, the identity will go back to Cognito and your app will be redirected to <REDIRECT_SIGN_IN_URL>?code=<SOME_CODE>, and Amplify will help you take the code from the query string and get a token from Authorization endpoint /oauth2/token
and boom, you get the token that can be used for signin (Amplify also automatically logged you in)
This allows users to use your app without registering themselves as users (and potentially to verify their email yada yada).They instead use their google / facebook identities. Federated Identities object won't give much info about the users like the usual Cognito user object, however. For the google federated identities, you only get their name, email and a link to their public profile picture.
- Amplify ui react provides a
GoogleSignInButton
component. This is used for federated identities signin. If you use this, make sure to add your google_client_id to the button component. - In the snippet above, I hack the appearance of a
GoogleSignInButton
because I used the User Pools social signin.