createResourceServer method

Future<CreateResourceServerResponse> createResourceServer({
  1. required String identifier,
  2. required String name,
  3. required String userPoolId,
  4. List<ResourceServerScopeType>? scopes,
})

Creates a new OAuth2.0 resource server and defines custom scopes within it. Resource servers are associated with custom scopes and machine-to-machine (M2M) authorization. For more information, see Access control with resource servers.

Learn more

May throw InternalErrorException. May throw InvalidParameterException. May throw LimitExceededException. May throw NotAuthorizedException. May throw OperationNotEnabledException. May throw ResourceNotFoundException. May throw TooManyRequestsException.

Parameter identifier : A unique resource server identifier for the resource server. The identifier can be an API friendly name like solar-system-data. You can also set an API URL like https://solar-system-data-api.example.com as your identifier.

Amazon Cognito represents scopes in the access token in the format $resource-server-identifier/$scope. Longer scope-identifier strings increase the size of your access tokens.

Parameter name : A friendly name for the resource server.

Parameter userPoolId : The ID of the user pool where you want to create a resource server.

Parameter scopes : A list of custom scopes. Each scope is a key-value map with the keys ScopeName and ScopeDescription. The name of a custom scope is a combination of ScopeName and the resource server Name in this request, for example MyResourceServerName/MyScopeName.

Implementation

Future<CreateResourceServerResponse> createResourceServer({
  required String identifier,
  required String name,
  required String userPoolId,
  List<ResourceServerScopeType>? scopes,
}) async {
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityProviderService.CreateResourceServer'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'Identifier': identifier,
      'Name': name,
      'UserPoolId': userPoolId,
      if (scopes != null) 'Scopes': scopes,
    },
  );

  return CreateResourceServerResponse.fromJson(jsonResponse.body);
}