Jump to Content

@aws-sdk/client-cognito-identity-provider

@aws-sdk/client-cognito-identity-provider

NPM version NPM downloads

Description

AWS SDK for JavaScript CognitoIdentityProvider Client for Node.js, Browser and React Native.

Using the Amazon Cognito user pools API, you can create a user pool to manage directories and users. You can authenticate a user to obtain tokens related to user identity and access policies.

This API reference provides information about user pools in Amazon Cognito user pools.

For more information, see the Amazon Cognito Documentation.

Installing

To install the this package, simply type add or install @aws-sdk/client-cognito-identity-provider using your favorite package manager:

  • npm install @aws-sdk/client-cognito-identity-provider
  • yarn add @aws-sdk/client-cognito-identity-provider
  • pnpm add @aws-sdk/client-cognito-identity-provider

Getting Started

Import

The AWS SDK is modulized by clients and commands. To send a request, you only need to import the CognitoIdentityProviderClient and the commands you need, for example AddCustomAttributesCommand:

// ES5 example
const {
CognitoIdentityProviderClient,
AddCustomAttributesCommand,
} = require("@aws-sdk/client-cognito-identity-provider");
// ES6+ example
import { CognitoIdentityProviderClient, AddCustomAttributesCommand } from "@aws-sdk/client-cognito-identity-provider";

Usage

To send a request, you:

  • Initiate client with configuration (e.g. credentials, region).
  • Initiate command with input parameters.
  • Call send operation on client with command object as input.
  • If you are using a custom http handler, you may call destroy() to close open connections.
// a client can be shared by different commands.
const client = new CognitoIdentityProviderClient({ region: "REGION" });

const params = {
/** input parameters */
};
const command = new AddCustomAttributesCommand(params);

Async/await

We recommend using await operator to wait for the promise returned by send operation as follows:

// async/await.
try {
const data = await client.send(command);
// process data.
} catch (error) {
// error handling.
} finally {
// finally.
}

Async-await is clean, concise, intuitive, easy to debug and has better error handling as compared to using Promise chains or callbacks.

Promises

You can also use Promise chaining to execute send operation.

client.send(command).then(
(data) => {
// process data.
},
(error) => {
// error handling.
}
);

Promises can also be called using .catch() and .finally() as follows:

client
.send(command)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
})
.finally(() => {
// finally.
});

Callbacks

We do not recommend using callbacks because of callback hell, but they are supported by the send operation.

// callbacks.
client.send(command, (err, data) => {
// process err and data.
});

v2 compatible style

The client can also send requests using v2 compatible style. However, it results in a bigger bundle size and may be dropped in next major version. More details in the blog post on modular packages in AWS SDK for JavaScript

import * as AWS from "@aws-sdk/client-cognito-identity-provider";
const client = new AWS.CognitoIdentityProvider({ region: "REGION" });

// async/await.
try {
const data = await client.addCustomAttributes(params);
// process data.
} catch (error) {
// error handling.
}

// Promises.
client
.addCustomAttributes(params)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
});

// callbacks.
client.addCustomAttributes(params, (err, data) => {
// process err and data.
});

Troubleshooting

When the service returns an exception, the error will include the exception information, as well as response metadata (e.g. request id).

try {
const data = await client.send(command);
// process data.
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$$metadata;
console.log({ requestId, cfId, extendedRequestId });
/**
* The keys within exceptions are also parsed.
* You can access them by specifying exception names:
* if (error.name === 'SomeServiceException') {
* const value = error.specialKeyInException;
* }
*/
}

Getting Help

Please use these community resources for getting help. We use the GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.

To test your universal JavaScript code in Node.js, browser and react-native environments, visit our code samples repo.

Contributing

This client code is generated automatically. Any modifications will be overwritten the next time the @aws-sdk/client-cognito-identity-provider package is updated. To contribute to client you can check our generate clients scripts.

License

This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information.

Client Commands (Operations List)

AddCustomAttributes

Command API Reference / Input / Output

AdminAddUserToGroup

Command API Reference / Input / Output

AdminConfirmSignUp

Command API Reference / Input / Output

AdminCreateUser

Command API Reference / Input / Output

AdminDeleteUser

Command API Reference / Input / Output

AdminDeleteUserAttributes

Command API Reference / Input / Output

AdminDisableProviderForUser

Command API Reference / Input / Output

AdminDisableUser

Command API Reference / Input / Output

AdminEnableUser

Command API Reference / Input / Output

AdminForgetDevice

Command API Reference / Input / Output

AdminGetDevice

Command API Reference / Input / Output

AdminGetUser

Command API Reference / Input / Output

AdminInitiateAuth

Command API Reference / Input / Output

AdminLinkProviderForUser

Command API Reference / Input / Output

AdminListDevices

Command API Reference / Input / Output

AdminListGroupsForUser

Command API Reference / Input / Output

AdminListUserAuthEvents

Command API Reference / Input / Output

AdminRemoveUserFromGroup

Command API Reference / Input / Output

AdminResetUserPassword

Command API Reference / Input / Output

AdminRespondToAuthChallenge

Command API Reference / Input / Output

AdminSetUserMFAPreference

Command API Reference / Input / Output

AdminSetUserPassword

Command API Reference / Input / Output

AdminSetUserSettings

Command API Reference / Input / Output

AdminUpdateAuthEventFeedback

Command API Reference / Input / Output

AdminUpdateDeviceStatus

Command API Reference / Input / Output

AdminUpdateUserAttributes

Command API Reference / Input / Output

AdminUserGlobalSignOut

Command API Reference / Input / Output

AssociateSoftwareToken

Command API Reference / Input / Output

ChangePassword

Command API Reference / Input / Output

ConfirmDevice

Command API Reference / Input / Output

ConfirmForgotPassword

Command API Reference / Input / Output

ConfirmSignUp

Command API Reference / Input / Output

CreateGroup

Command API Reference / Input / Output

CreateIdentityProvider

Command API Reference / Input / Output

CreateResourceServer

Command API Reference / Input / Output

CreateUserImportJob

Command API Reference / Input / Output

CreateUserPool

Command API Reference / Input / Output

CreateUserPoolClient

Command API Reference / Input / Output

CreateUserPoolDomain

Command API Reference / Input / Output

DeleteGroup

Command API Reference / Input / Output

DeleteIdentityProvider

Command API Reference / Input / Output

DeleteResourceServer

Command API Reference / Input / Output

DeleteUser

Command API Reference / Input / Output

DeleteUserAttributes

Command API Reference / Input / Output

DeleteUserPool

Command API Reference / Input / Output

DeleteUserPoolClient

Command API Reference / Input / Output

DeleteUserPoolDomain

Command API Reference / Input / Output

DescribeIdentityProvider

Command API Reference / Input / Output

DescribeResourceServer

Command API Reference / Input / Output

DescribeRiskConfiguration

Command API Reference / Input / Output

DescribeUserImportJob

Command API Reference / Input / Output

DescribeUserPool

Command API Reference / Input / Output

DescribeUserPoolClient

Command API Reference / Input / Output

DescribeUserPoolDomain

Command API Reference / Input / Output

ForgetDevice

Command API Reference / Input / Output

ForgotPassword

Command API Reference / Input / Output

GetCSVHeader

Command API Reference / Input / Output

GetDevice

Command API Reference / Input / Output

GetGroup

Command API Reference / Input / Output

GetIdentityProviderByIdentifier

Command API Reference / Input / Output

GetSigningCertificate

Command API Reference / Input / Output

GetUICustomization

Command API Reference / Input / Output

GetUser

Command API Reference / Input / Output

GetUserAttributeVerificationCode

Command API Reference / Input / Output

GetUserPoolMfaConfig

Command API Reference / Input / Output

GlobalSignOut

Command API Reference / Input / Output

InitiateAuth

Command API Reference / Input / Output

ListDevices

Command API Reference / Input / Output

ListGroups

Command API Reference / Input / Output

ListIdentityProviders

Command API Reference / Input / Output

ListResourceServers

Command API Reference / Input / Output

ListTagsForResource

Command API Reference / Input / Output

ListUserImportJobs

Command API Reference / Input / Output

ListUserPoolClients

Command API Reference / Input / Output

ListUserPools

Command API Reference / Input / Output

ListUsers

Command API Reference / Input / Output

ListUsersInGroup

Command API Reference / Input / Output

ResendConfirmationCode

Command API Reference / Input / Output

RespondToAuthChallenge

Command API Reference / Input / Output

RevokeToken

Command API Reference / Input / Output

SetRiskConfiguration

Command API Reference / Input / Output

SetUICustomization

Command API Reference / Input / Output

SetUserMFAPreference

Command API Reference / Input / Output

SetUserPoolMfaConfig

Command API Reference / Input / Output

SetUserSettings

Command API Reference / Input / Output

SignUp

Command API Reference / Input / Output

StartUserImportJob

Command API Reference / Input / Output

StopUserImportJob

Command API Reference / Input / Output

TagResource

Command API Reference / Input / Output

UntagResource

Command API Reference / Input / Output

UpdateAuthEventFeedback

Command API Reference / Input / Output

UpdateDeviceStatus

Command API Reference / Input / Output

UpdateGroup

Command API Reference / Input / Output

UpdateIdentityProvider

Command API Reference / Input / Output

UpdateResourceServer

Command API Reference / Input / Output

UpdateUserAttributes

Command API Reference / Input / Output

UpdateUserPool

Command API Reference / Input / Output

UpdateUserPoolClient

Command API Reference / Input / Output

UpdateUserPoolDomain

Command API Reference / Input / Output

VerifySoftwareToken

Command API Reference / Input / Output

VerifyUserAttribute

Command API Reference / Input / Output