What the settings mean in AWS Cognito User Pool App Client

Here is my take on the matter.

App client has several Auth Flow Configurations.

1. Enable username password auth for admin APIs for authentication (ALLOW_ADMIN_USER_PASSWORD_AUTH)

This enables Server-Side Authentication Flow. If you don't have an end-user app, but instead you're using a secure back end or server-side app.

enter image description here

2. Enable lambda trigger-based custom authentication (ALLOW_CUSTOM_AUTH)

This enables the Custom Authentication Flow. This can help you create a challenge/response-based authentication model using AWS Lambda triggers. https://docs.aws.amazon.com/cognito/latest/developerguide/user-pool-lambda-challenge.html

Under User Pools -> Triggers you can see many lambda functions. You can use Create Auth Challenge, Define Auth Challenge and Verify Auth Challenge Response functions to create a custom authentication flow.

3. Enable username password based authentication (ALLOW_USER_PASSWORD_AUTH)

This enables Client Side Authentication Flow that uses user password-based authentication. In this flow, Cognito receives the password in the request.

You can use AWS Mobile SDK for Android, AWS Mobile SDK for iOS, or AWS SDK for JavaScript to implement this.

4. Enable SRP (secure remote password) protocol based authentication (ALLOW_USER_SRP_AUTH)

This is similar to the above flow in section 3. except for the password verification. This flow uses the SRP protocol to verify passwords.

http://srp.stanford.edu/whatisit.html https://docs.aws.amazon.com/cognito-user-identity-pools/latest/APIReference/API_UserPoolClientType.html

enter image description here

5. Enable refresh token based authentication (ALLOW_REFRESH_TOKEN_AUTH)

After successful authentication, Amazon Cognito returns user pool tokens(Three tokens) to your app. You can use the tokens to grant your users access to your own server-side resources, or to the Amazon API Gateway. Or, you can exchange them for temporary AWS credentials to access other AWS services.

The three tokens are ID Token(JWT), Access Token, Refresh Token. The refresh token can be used to retrieve new ID and access tokens. Once you login to a mobile app, you are not needed to log in each time when you close and open the application and this functionality is implemented using refresh tokens.

https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-using-tokens-with-identity-providers.html

What about Amazon Cognito hosted UI ?

App clients can be configured to use built-in Cognito webpages for signing up and signing in users. When using the hosted UI you can enable both the Authorization code grant and the Implicit code grant, and then use each grant as needed.

https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-app-idp-settings.html


Here is my attempt at explaining these options. Before that I would like to briefly mention about Oauth2, which is the protocol on which AWS Cognito is based.

In the context of AWS Cognito, Cognito itself is the Authentication (OAuth) server and also the Resource server (because we create users in Cognito user pool) and your app would be the Client (which sends the authentication request). The client has to first register itself with the OAuth server - this is what is being done in the "App clients" section of Cognito.

The recommended OAuth2 flow is Authorization Code Grant flow. In this flow,

i) The Client sends username/password to the OAuth Server.

ii) The OAuth server validates and calls back the client with a authorization code.

iii) The Client again sends this code back to the OAuth server

iv) The OAuth server sends the tokens to the Client.

Please read the above linked article for more explanation on OAuth2.

Now explaining the options in Cognito App Client settings:

1. Enable sign-in API for server-based authentication

With this option, your client app can directly receive the tokens without having the additional step of first getting the authorization code.

There are Cognito APIs like AdminInitiateAuth, Admin-* which does this. However, these APIs require AWS admin credentials. Hence usually these calls are done by the backend server of the client app. The front-end can pass the username/password to the backend and the backend server can communicate with AWS Cognito and authorize the user.

2. Only allow Custom Authentication

Here you don't use the OAuth provided authorization code grant flow. Instead, you can define your own steps and challenges. Your client app can ask a secret question etc, before authenticating and giving tokens.

3. Enable username-password (non-SRP) flow for app-based authentication

This is the least safe flow. This skips the part of returning the authorization code and directly returns the tokens back to the client.

I hope this explains.