Defining resource servers for your user pool
Once you configure a domain for your user pool, Amazon Cognito automatically provisions a hosted web UI with which you can add sign-up and sign-in pages to your app. For more information see Step 2. Add an app client and set up the hosted UI.
A resource server is a server for access-protected resources. It
handles authenticated requests from an app that has an access token. Typically the resource
server provides a CRUD
Your resource server must verify the access token signature and expiration date before
processing any claims inside the token. For more information about verifying and using
user pool tokens, see Integrating Amazon Cognito User Pools with API Gateway
A scope is a level of access that an app can request to a resource. For example, if you have a resource server for photos, it might define two scopes: one for read access to the photos and one for write/delete access. When the app makes an API call to request access and passes an access token, the token will have one or more scopes embedded inside of it.
Overview
Amazon Cognito allows app developers to create their own OAuth2.0 resource servers, and define
custom scopes within them. Custom scopes can then be associated with a client, and the
client can request those scopes in OAuth2.0 authorization code grant flow, implicit flow,
and client credentials flow. Custom scopes are added in the scope
claim in the
access token. A client can use the access token against its resource server, which makes the
authorization decision based on the scopes present in the token. For more information about
access token scope, see Using Tokens
with User Pools.
Your resource server must verify the access token signature and expiration date before processing any claims inside the token.
An app client can only use the client credentials flow if the app client has a client secret.
Managing the Resource Server and Custom Scopes
When creating a resource server, you must provide a resource server name and a resource server identifier. For each scope you create in the resource server, you must provide the scope name and description.
Example:
-
Name
: A friendly name for the resource server, such asWeather API
orPhoto API
. -
Identifier
: A unique identifier for the resource server. This can be an HTTPS endpoint where your resource server is located. For example,https://my-weather-api.example.com
-
Scope Name
: The scope name. For example,weather.read
-
Scope Description
: A brief description the scope. For example,Retrieve weather information
.
When a client app requests a custom scope in any of the OAuth2.0 flows, it must request
the full identifier for the scope, which is
.
For example, if the resource server identifier is
resourceServerIdentifier
/scopeName
https://myphotosapi.example.com
and the scope name is
photos.read
, the client app must request
https://myphotosapi.example.com/photos.read
at runtime.
Deleting a scope from a resource server does not delete its association with all clients; instead, the scope is marked inactive. If a client app requests the deleted scope at runtime, the scope is ignored and is not included in the access token. If the scope is re-added later, then it is again included in the access token.
If a scope is removed from a client, the association between client and scope is deleted. If a client requests a disallowed scope at runtime, an error is returned and an access token isn't issued.
You can use the AWS Management Console, API, or CLI to define resource servers and scopes for your user pool.
Defining a resource server for your user pool (AWS Management Console)
You can use the AWS Management Console to define a resource server for your user pool.
Defining a resource server for your user pool (AWS CLI and AWS API)
Use the following commands to specify resource server settings for your user pool.
To create a resource server
-
AWS CLI:
aws cognito-idp create-resource-server
-
AWS API: CreateResourceServer
To get information about your resource server settings
-
AWS CLI:
aws cognito-idp describe-resource-server
-
AWS API: DescribeResourceServer
To list information about all resource servers for your user pool
-
AWS CLI:
aws cognito-idp list-resource-servers
-
AWS API: ListResourceServers
To delete a resource server
-
AWS CLI:
aws cognito-idp delete-resource-server
-
AWS API: DeleteResourceServer
To update the settings for a resource server
-
AWS CLI:
aws cognito-idp update-resource-server
-
AWS API: UpdateResourceServer