Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
@aws-sdk/client-cognito-identity-provider
Advanced tools
AWS SDK for JavaScript Cognito Identity Provider Client for Node.js, Browser and React Native
@aws-sdk/client-cognito-identity-provider is a part of the AWS SDK for JavaScript. It allows developers to interact with Amazon Cognito, a service that provides user sign-up, sign-in, and access control. This package enables you to manage user pools, authenticate users, and handle user data securely.
User Sign-Up
This feature allows you to register a new user in a Cognito User Pool. The code sample demonstrates how to use the SignUpCommand to create a new user with specified attributes.
const { CognitoIdentityProviderClient, SignUpCommand } = require('@aws-sdk/client-cognito-identity-provider');
const client = new CognitoIdentityProviderClient({ region: 'us-west-2' });
const signUp = async () => {
const params = {
ClientId: 'your-client-id',
Username: 'username',
Password: 'password',
UserAttributes: [
{
Name: 'email',
Value: 'user@example.com'
}
]
};
const command = new SignUpCommand(params);
try {
const data = await client.send(command);
console.log('Sign-Up successful:', data);
} catch (error) {
console.error('Error during sign-up:', error);
}
};
signUp();
User Authentication
This feature allows you to authenticate a user using their username and password. The code sample demonstrates how to use the InitiateAuthCommand to authenticate a user and retrieve authentication tokens.
const { CognitoIdentityProviderClient, InitiateAuthCommand } = require('@aws-sdk/client-cognito-identity-provider');
const client = new CognitoIdentityProviderClient({ region: 'us-west-2' });
const authenticateUser = async () => {
const params = {
AuthFlow: 'USER_PASSWORD_AUTH',
ClientId: 'your-client-id',
AuthParameters: {
USERNAME: 'username',
PASSWORD: 'password'
}
};
const command = new InitiateAuthCommand(params);
try {
const data = await client.send(command);
console.log('Authentication successful:', data);
} catch (error) {
console.error('Error during authentication:', error);
}
};
authenticateUser();
Password Reset
This feature allows you to initiate a password reset for a user. The code sample demonstrates how to use the ForgotPasswordCommand to start the password reset process, which sends a verification code to the user's email or phone.
const { CognitoIdentityProviderClient, ForgotPasswordCommand } = require('@aws-sdk/client-cognito-identity-provider');
const client = new CognitoIdentityProviderClient({ region: 'us-west-2' });
const resetPassword = async () => {
const params = {
ClientId: 'your-client-id',
Username: 'username'
};
const command = new ForgotPasswordCommand(params);
try {
const data = await client.send(command);
console.log('Password reset initiated:', data);
} catch (error) {
console.error('Error during password reset:', error);
}
};
resetPassword();
The amazon-cognito-identity-js package is a JavaScript library for Amazon Cognito. It provides similar functionalities to @aws-sdk/client-cognito-identity-provider, such as user sign-up, sign-in, and password management. However, it is more focused on client-side applications and provides a higher-level abstraction for interacting with Cognito.
cognito-express is a middleware for Express.js that simplifies the process of verifying Amazon Cognito JWT tokens. It is useful for server-side applications that need to authenticate and authorize users based on their Cognito tokens. Unlike @aws-sdk/client-cognito-identity-provider, it does not provide user management functionalities.
AWS Amplify is a comprehensive library that provides a set of tools and services for building cloud-enabled applications. It includes support for Amazon Cognito for authentication and user management, along with other AWS services. AWS Amplify offers a higher-level abstraction and is designed to simplify the integration of various AWS services into your application.
AWS SDK for JavaScript CognitoIdentityProvider Client for Node.js, Browser and React Native.
With the Amazon Cognito user pools API, you can configure user pools and authenticate users. To authenticate users from third-party identity providers (IdPs) in this API, you can link IdP users to native user profiles. Learn more about the authentication and authorization of federated users at Adding user pool sign-in through a third party and in the User pool federation endpoints and hosted UI reference.
This API reference provides detailed information about API operations and object types in Amazon Cognito.
Along with resource management operations, the Amazon Cognito user pools API includes classes of operations and authorization models for client-side and server-side authentication of users. You can interact with operations in the Amazon Cognito user pools API as any of the following subjects.
An administrator who wants to configure user pools, app clients, users, groups, or other user pool functions.
A server-side app, like a web application, that wants to use its Amazon Web Services privileges to manage, authenticate, or authorize a user.
A client-side app, like a mobile app, that wants to make unauthenticated requests to manage, authenticate, or authorize a user.
For more information, see Using the Amazon Cognito user pools API and user pool endpoints in the Amazon Cognito Developer Guide.
With your Amazon Web Services SDK, you can build the logic to support operational flows in every use
case for this API. You can also make direct REST API requests to Amazon Cognito user pools service endpoints. The following links can get you started
with the CognitoIdentityProvider
client in other supported Amazon Web Services
SDKs.
To get started with an Amazon Web Services SDK, see Tools to Build on Amazon Web Services. For example actions and scenarios, see Code examples for Amazon Cognito Identity Provider using Amazon Web Services SDKs.
To install 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
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 ListDevicesCommand
:
// ES5 example
const { CognitoIdentityProviderClient, ListDevicesCommand } = require("@aws-sdk/client-cognito-identity-provider");
// ES6+ example
import { CognitoIdentityProviderClient, ListDevicesCommand } from "@aws-sdk/client-cognito-identity-provider";
To send a request, you:
send
operation on client with command object as input.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 ListDevicesCommand(params);
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.
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.
});
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.
});
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.listDevices(params);
// process data.
} catch (error) {
// error handling.
}
// Promises.
client
.listDevices(params)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
});
// callbacks.
client.listDevices(params, (err, data) => {
// process err and data.
});
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;
* }
*/
}
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.
aws-sdk-js
on AWS Developer Blog.aws-sdk-js
.To test your universal JavaScript code in Node.js, browser and react-native environments, visit our code samples repo.
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.
This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information.
FAQs
AWS SDK for JavaScript Cognito Identity Provider Client for Node.js, Browser and React Native
The npm package @aws-sdk/client-cognito-identity-provider receives a total of 877,432 weekly downloads. As such, @aws-sdk/client-cognito-identity-provider popularity was classified as popular.
We found that @aws-sdk/client-cognito-identity-provider demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.