Next: Identity Pool API, Previous: User Pool API, Up: Cognito APIs [Index]
Once a domain has been configured for your user pool, Amazon Cognito hosts an authentication server that allows you to add sign-up and sign-in webpages to your app.
This section contains the HTTPS contract to the Amazon Cognito authentication server from a user pool client, including sample requests and responses. It describes the expected behavior from the authentication server for positive and negative conditions.
In addition to the server contract REST API, Amazon Cognito also provides Auth SDKs for Android, iOS, and JavaScript that make it easier to form requests and interact with the server.
https://docs.aws.amazon.com/cognito/latest/developerguide/authorization-endpoint.html
The /oauth2/authorize endpoint signs the user in.
GET /oauth2/authorize
The /oauth2/authorize
endpoint only supports HTTPS ‘GET’. The user pool
client typically makes this request through a browser. Web browsers include
Chrome or Firefox. Android browsers include Custom Chrome Tab. iOS browsers
include Safari View Control.
The authorization server requires HTTPS instead of HTTP as the protocol when accessing the authorization endpoint.
Required
The response type. Must be ‘code’ or ‘token’. Indicates whether the client wants an authorization code (authorization code grant flow) for the end user or directly issues tokens for end user (implicit flow).
Required
Must be a pre-registered client in the user pool and must be enabled for federation.
Required
The URL to which the authentication server redirects the browser after authorization has been granted by the user. A redirect URI must:
Amazon Cognito requires HTTPS over HTTP except for http://localhost
for
testing purposes only. App callback URLs such as
myapp://example
are also supported.
Optional but recommended
An opaque value the clients adds to the initial request. The authorization server includes this value when redirecting back to the client. This value must be used by the client to prevent CSRF attacks.
Optional
Used by the developer to directly authenticate with a specific provider.
Optional
Used by the developer to map to a provider name without exposing the provider name.
Optional
Can be a combination of any system-reserved scopes or custom scopes associated with a client. Scopes must be separated by spaces. Any scope used must be preassociated with the client or it will be ignored at runtime. If the client doesn’t request any scopes, the authentication server uses all scopes associated with the client.
System reserved scopes are:
An ID token is only returned if openid scope is requested. The access token can be only used against Amazon Cognito User Pools if aws.cognito.signin.user.admin scope is requested. The phone, email, and profile scopes can only be requested if openid scope is also requested. These scopes dictate the claims that go inside the ID token.
Optional
The method used to generate the challenge. Amazon Cognito authentication server supports only ‘S256’.
Required only when the code_challenge_method is specified.
The generated challenge from the code_verifier.
GET https://mydomain.auth.us-east-1.amazoncognito.com/oauth2/authorize? response_type=code& client_id=ad398u21ijw3s9w3939& redirect_uri=https://YOUR_APP/redirect_uri& state=STATE& scope=openid+profile+aws.cognito.signin.user.admin
The Amazon Cognito authentication server redirects back to your app with the authorization code and state. The code and state must be returned in the query string parameters and not in the fragment.
the part of a web request that appears after a ’?’ character; the string can contain one or more parameters separated by ’&’ characters.
the part of a web request that appears after a ’#’ character to specify a subsection of a document.
HTTP/1.1 302 Found Location: https://YOUR_APP/redirect_uri?code=AUTHORIZATION_CODE&state=STATE
GET https://mydomain.auth.us-east-1.amazoncognito.com/oauth2/authorize? response_type=code& client_id=ad398u21ijw3s9w3939& redirect_uri=https://YOUR_APP/redirect_uri& state=STATE& scope=aws.cognito.signin.user.admin& code_challenge_method=S256& code_challenge=CODE_CHALLENGE
HTTP/1.1 302 Found Location: https://YOUR_APP/redirect_uri?code=AUTHORIZATION_CODE&state=STATE
GET https://mydomain.auth.us-east-1.amazoncognito.com/oauth2/authorize? response_type=token& client_id=ad398u21ijw3s9w3939& redirect_uri=https://YOUR_APP/redirect_uri& state=STATE& scope=aws.cognito.signin.user.admin
The Amazon Cognito authorization server redirects back to your app with access token. Since ‘openid’ scope was not requested, an ID token is not returned. A refresh token is never returned in this flow. Token and state are returned in the fragment and not in the query string.
HTTP/1.1 302 Found Location: https://YOUR_APP/redirect_uri#access_token=ACCESS_TOKEN&token_type=bearer&expires_in=3600&state=STATE
GET https://mydomain.auth.us-east-1.amazoncognito.com/oauth2/authorize? response_type=token& client_id=ad398u21ijw3s9w3939& redirect_uri=https://YOUR_APP/redirect_uri& state=STATE& scope=aws.cognito.signin.user.admin+openid+profile
The authorization server redirects back to your app with access token and ID token (because ‘openid’ scope was included).
HTTP/1.1 302 Found Location: https://YOUR_APP/redirect_ur#id_token=ID_TOKEN&access_token=ACCESS_TOKEN&token_type=bearer&expires_in=3600&state=STATE
The following are examples of negative responses:
HTTP 1.1 302 Found Location: https://client_redirect_uri?error=invalid_request
HTTP 1.1 302 Found Location: https://client_redirect_uri?error=unauthorized_client
HTTP 1.1 302 Found Location: https://client_redirect_uri?error=invalid_scope
HTTP 1.1 302 Found Location: https://client_redirect_uri?error=server_error
HTTP 1.1 302 Found Location: https://client_redirect_uri? error=invalid_request& error_description=Timeout+occurred+in+calling+IdP+token+endpoint
HTTP 1.1 302 Found Location: https://client_redirect_uri? error=invalid_request& error_description=error_description=Timeout+in+calling+jwks+uri
HTTP 1.1 302 Found Location: https://client_redirect_uri? error=invalid_request& error_description=[IdP name]+Error+-+[status code]+error getting token
HTTP 1.1 302 Found Location: https://client_redirect_uri? error=invalid_request& error_description=Google+Error+-+[status code]+[Google provided error code]
HTTP 1.1 302 Found Location: https://client_redirect_uri?error=invalid_request&error_description=Connection+reset
HTTP 1.1 302 Found Location: https://client_redirect_uri?error=invalid_request&error_description=Read+timed+out
https://docs.aws.amazon.com/cognito/latest/developerguide/login-endpoint.html
The /login
endpoint signs the user in. It loads the login page and presents
the authentication options configured for the client to the user.
The /login
endpoint only supports HTTPS GET. The user pool client makes this
request through a system browser. System browsers for JavaScript include
Chrome or Firefox. Android browsers include Custom Chrome Tab. iOS browsers
include Safari View Control.
Required. The app client ID for your app. To obtain an app client ID, register the app in the user pool.
Required. The URI where the user is redirected after a successful authentication. It should be configured on ‘response_type’ of the specified ‘client_id’.
Required. The OAuth response type, which can be code for code grant flow and token for implicit flow.
Optional but recommended. Can be a combination of any system-reserved scopes or custom scopes associated with a client. Scopes must be separated by spaces. If the client doesn’t request any scopes, the authentication server uses all scopes associated with the client.
System reserved scopes are:
An ID token is only returned if an ‘openid’ scope is requested. The access token can only be used against Amazon Cognito user pools if an ‘aws.cognito.signin.user.admin’ scope is requested. The ‘phone’, ‘email’, and ‘profile’ scopes can only be requested if an ‘openid’ scope is also requested. These scopes dictate the claims that go inside the ID token.
Any scope used must be preassociated with the client or it is ignored at runtime.
This example displays the login screen.
GET https://mydomain.auth.us-east-1.amazoncognito.com/login? response_type=code& client_id=ad398u21ijw3s9w3939& redirect_uri=https://YOUR_APP/redirect_uri& state=STATE& scope=openid+profile+aws.cognito.signin.user.admin
Next: Identity Pool API, Previous: User Pool API, Up: Cognito APIs [Index]