DEV Community

Sathish P
Sathish P

Posted on

Amaon cognito

What does Cognito?
Give users an identity to interact with web or mobile application
Cognito user pools:

  • sign in functionality for all users
  • integrate with API gateway & application load balancer

Cognito identity pools(Federated Identity):

  • provides temporary AWS credentials to users so they can access AWS resources directly
  • integrate with cognito user pools as an identity provider

Features:

  • create a serverless database of user for your web and mobile apps
  • simple login:username(or email)/password combination
  • password reset
  • Email and phone number verification
  • MFA
  • federated identities: users from facebook,google,SAML
  • feature:block users if credentials are compromised elsewhere
  • login sends back a JSON Web Token(JWT) Daigram:

Image description

Image description

Image description

Image description

choosing to create a user pool
Authentication can be done in 2 ways

  1. cognito user pool(username &password, email)
  2. federation identity providers(google,facebook,SAML)

Image description

password can be default or customied

Image description
Multi factor Authentication can be chosen whether it should be mandatory, option or not required

Image description

account recovery can be enable or diable
if enable, in which way we can recover through forgot password can be chosen

Image description

enabling new users to register for your app(enable self registartion)

Image description
verification

Image description
we can add the reuired attributes to the signup page(if reuired)
Image description

if any other custom attributes needs to be added we can

Image description

configure how user pool sends message to users

Image description

Image description
call back urls can be specified after successful login

Image description
can review once and can be created

Image description

In sign in experience tab if required can add identity provider

Image description
click on view hosted to create a user

Image description

this will open the login page in new tab once sign up with the page sends verification SMS to the registered mail. after successful login, navigate to the call back url page

Image description

we can specify lambda triggers for any of the functionality

Image description

Image description

cognito user pools - lambda triggers

Image description

Hosted Authentication UI

  • cognito has hosted authentication UI that can be add to your own app to handle signup and sign in workflows
  • using the hosted ui, your app can integrate with social login, OIDC or SAML
  • can be customised with custom logo and custom CSS

Hosted UI custom domain

  • for custom domains you must create ACM certificate(us-east-1)
  • custom domain is defined in app integration section

JSON Web Token(JWT)

  • CUP issues JWT tokens
    • headers
    • paload
    • signature
  • the signature can be verified to ensure the JWT token can be trusted

Application Load Balancer - Authenticate users
your application load balancer can securely authenticate users

  • offload the work of authenticating users to load balancer
    • your application can focus on the business logic
      • authenticate users through:
      • identity provider(IdP): OpenIDConnect(OIDC) Compliant
      • cognito user pools:
        • social IdP's such as amazon, facebook or google
        • corporate identities using SAML, LDAP or Microsoft AD
  • must use an HTTPS listener to set authenticate-oidc and authenticate-cognito rules
  • onunauthenticated request- authenticate(default),deny,allow

Application Load Balancer - Cognito Auth

Image description

Application Load Balancer - OIDC Auth

Image description

Cognito Identity pools - diagram

Image description

cognito identity pools - diagram with CUP

Image description

Creating Identity pool:

Image description

we can enable the unauthenticated identities and can change the authentication flow. by default it will follow enhanced, we can change to basic flow as well

Image description

we can select authentication providers

Image description

pool id and client id needs to be copied from previous steps where we have created the user pool

after creating identity pool it will ask us to allow two IAM roles

  1. for authenticates identities
  2. unauthenticated identities

Image description

we can select the platform where we are installing the SDK and after installation if we run the below code it will generate AWS credentials

Image description

from the dashboard we can check number of authenticated and unauthenticated identities

Image description

we can customize the IAM roles by navigatin to IAM-> roles

we can see created IAM roles in previous step. by hitting on edit we can customize.

Note:- User pools are for authentication, identity pools for authorisation.

Top comments (1)

Collapse
 
vdelitz profile image
vdelitz

Looks quite complicated for a startup that wouldn't have much resources or complex requirements. Would you still recommend AWS Cognito in that case or something else?