# @aws-sdk/client-cognito-identity-browser

> Browser SDK for Amazon Cognito Identity

Latest version **0.1.0-preview.2** (published 2019-01-25) · Apache-2.0 license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install @aws-sdk/client-cognito-identity-browser
pnpm add @aws-sdk/client-cognito-identity-browser
yarn add @aws-sdk/client-cognito-identity-browser
bun add @aws-sdk/client-cognito-identity-browser
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.0-preview.2 |
| Published | 2019-01-25 |
| First published | 2018-11-19 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 23 |
| Unpacked size | 342.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | AWS SDK for JavaScript Team |
| Maintainers | amzn-oss, aws-sdk-bot, cjradek, jpeddicord, zheallan |

## Links

- npm: https://www.npmjs.com/package/@aws-sdk/client-cognito-identity-browser
- npm.io page: https://npm.io/package/@aws-sdk/client-cognito-identity-browser

## Dependencies (23)

- [tslib](https://npm.io/package/tslib.md) ^1.8.0
- [@aws-sdk/types](https://npm.io/package/@aws-sdk/types.md) ^0.1.0-preview.1
- [@aws-sdk/json-parser](https://npm.io/package/@aws-sdk/json-parser.md) ^0.1.0-preview.1
- [@aws-sdk/core-handler](https://npm.io/package/@aws-sdk/core-handler.md) ^0.1.0-preview.1
- [@aws-sdk/json-builder](https://npm.io/package/@aws-sdk/json-builder.md) ^0.1.0-preview.1
- [@aws-sdk/signature-v4](https://npm.io/package/@aws-sdk/signature-v4.md) ^0.1.0-preview.2
- [@aws-sdk/config-resolver](https://npm.io/package/@aws-sdk/config-resolver.md) ^0.1.0-preview.1
- [@aws-sdk/middleware-stack](https://npm.io/package/@aws-sdk/middleware-stack.md) ^0.1.0-preview.2
- [@aws-sdk/retry-middleware](https://npm.io/package/@aws-sdk/retry-middleware.md) ^0.1.0-preview.1
- [@aws-crypto/sha256-browser](https://npm.io/package/@aws-crypto/sha256-browser.md) ^0.1.0-preview.1
- [@aws-sdk/protocol-json-rpc](https://npm.io/package/@aws-sdk/protocol-json-rpc.md) ^0.1.0-preview.2
- [@aws-sdk/util-utf8-browser](https://npm.io/package/@aws-sdk/util-utf8-browser.md) ^0.1.0-preview.1
- [@aws-sdk/fetch-http-handler](https://npm.io/package/@aws-sdk/fetch-http-handler.md) ^0.1.0-preview.1
- [@aws-sdk/signing-middleware](https://npm.io/package/@aws-sdk/signing-middleware.md) ^0.1.0-preview.2
- [@aws-sdk/url-parser-browser](https://npm.io/package/@aws-sdk/url-parser-browser.md) ^0.1.0-preview.1
- [@aws-sdk/util-base64-browser](https://npm.io/package/@aws-sdk/util-base64-browser.md) ^0.1.0-preview.1
- [@aws-sdk/middleware-serializer](https://npm.io/package/@aws-sdk/middleware-serializer.md) ^0.1.0-preview.1
- [@aws-sdk/json-error-unmarshaller](https://npm.io/package/@aws-sdk/json-error-unmarshaller.md) ^0.1.0-preview.2
- [@aws-sdk/util-user-agent-browser](https://npm.io/package/@aws-sdk/util-user-agent-browser.md) ^0.1.0-preview.2
- [@aws-sdk/stream-collector-browser](https://npm.io/package/@aws-sdk/stream-collector-browser.md) ^0.1.0-preview.1
- [@aws-sdk/util-body-length-browser](https://npm.io/package/@aws-sdk/util-body-length-browser.md) ^0.1.0-preview.1
- [@aws-sdk/middleware-content-length](https://npm.io/package/@aws-sdk/middleware-content-length.md) ^0.1.0-preview.1
- [@aws-sdk/middleware-header-default](https://npm.io/package/@aws-sdk/middleware-header-default.md) ^0.1.0-preview.1

## Recent versions

- 0.1.0-preview.2 (latest) — 2019-01-25
- 0.1.0-preview.10 (preview) — 2019-11-19
- 0.1.0-preview.9 — 2019-10-30
- 0.1.0-preview.8 — 2019-10-29
- 0.1.0-preview.7 — 2019-09-19
- 0.1.0-preview.6 — 2019-09-09
- 0.1.0-preview.5 — 2019-07-12
- 0.1.0-preview.4 — 2019-04-19
- 0.1.0-preview.3 — 2019-03-27
- 0.1.0-preview.1 — 2018-11-19

## README

# @aws-sdk/client-cognito-identity-browser

## Description

<fullname>Amazon Cognito</fullname> <p>Amazon Cognito is a web service that delivers scoped temporary credentials to mobile devices and other untrusted environments. Amazon Cognito uniquely identifies a device and supplies the user with a consistent identity over the lifetime of an application.</p> <p>Using Amazon Cognito, you can enable authentication with one or more third-party identity providers (Facebook, Google, or Login with Amazon), and you can also choose to support unauthenticated access from your app. Cognito delivers a unique identifier for each user and acts as an OpenID token provider trusted by AWS Security Token Service (STS) to access temporary, limited-privilege AWS credentials.</p> <p>To provide end-user credentials, first make an unsigned call to <a>GetId</a>. If the end user is authenticated with one of the supported identity providers, set the <code>Logins</code> map with the identity provider token. <code>GetId</code> returns a unique identifier for the user.</p> <p>Next, make an unsigned call to <a>GetCredentialsForIdentity</a>. This call expects the same <code>Logins</code> map as the <code>GetId</code> call, as well as the <code>IdentityID</code> originally returned by <code>GetId</code>. Assuming your identity pool has been configured via the <a>SetIdentityPoolRoles</a> operation, <code>GetCredentialsForIdentity</code> will return AWS credentials for your use. If your pool has not been configured with <code>SetIdentityPoolRoles</code>, or if you want to follow legacy flow, make an unsigned call to <a>GetOpenIdToken</a>, which returns the OpenID token necessary to call STS and retrieve AWS credentials. This call expects the same <code>Logins</code> map as the <code>GetId</code> call, as well as the <code>IdentityID</code> originally returned by <code>GetId</code>. The token returned by <code>GetOpenIdToken</code> can be passed to the STS operation <a href="http://docs.aws.amazon.com/STS/latest/APIReference/API_AssumeRoleWithWebIdentity.html">AssumeRoleWithWebIdentity</a> to retrieve AWS credentials.</p> <p>If you want to use Amazon Cognito in an Android, iOS, or Unity application, you will probably want to make API calls via the AWS Mobile SDK. To learn more, see the <a href="http://docs.aws.amazon.com/mobile/index.html">AWS Mobile SDK Developer Guide</a>.</p>

## Installing

To install the this package using NPM, simply type the following into a terminal window: 

```
npm install @aws-sdk/client-cognito-identity-browser
```

## Getting Started

### Import

The AWS SDK is modulized by clients and commends in CommonJS modules. To send a request, you only need to import the client(`CognitoIdentityClient`) and the commands you need, for example `CreateIdentityPoolCommand`:

```javascript
//javascript
const { CognitoIdentityClient } = require('@aws-sdk/client-cognito-identity-browser/CognitoIdentityClient');
const { CreateIdentityPoolCommand } = require('@aws-sdk/client-cognito-identity-browser/CreateIdentityPoolCommand');
```

```javascript
//typescript
const { CognitoIdentityClient } = import '@aws-sdk/client-cognito-identity-browser/CognitoIdentityClient';
const { CreateIdentityPoolCommand } = import '@aws-sdk/client-cognito-identity-browser/commands/CreateIdentityPoolCommand';
```

### Usage

To send a request, you:

* Initiate client with configurations.(credentials, region). For more information you can refer to the [API reference][].
* Initiate command with input parameters.
* Call `send` operation of client with command object as input.
* If you are using a custom http handler, you may call `destroy()` to close open connections. 

```javascript
const cognitoIdentity = new CognitoIdentityClient({region: 'region'});
//clients can be shared by different commands
const params = {
    IdentityPoolName: /**a string value*/,
    AllowUnauthenticatedIdentities: /**a boolean value*/,
};
const createIdentityPoolCommand = new CreateIdentityPoolCommand(params);
cognitoIdentity.send(createIdentityPoolCommand).then(data => {
    // do something
}).catch(error => {
    // error handling
})
```

Besides using promise style, there are 2 other ways to send a request:

```javascript
// async/await
try {
    const data = await cognitoIdentity.send(createIdentityPoolCommand);
    // do something
} catch(error) {
    // error handling
}
```

```javascript
// callback
cognitoIdentity.send(createIdentityPoolCommand, (err, data) => {
    //do something
})
```
 
Besides using `send()`, the SDK can also send requests using the simplified callback style in version 2 of the SDK.

```javascript
import * as AWS from '@aws-sdk/@aws-sdk/client-cognito-identity-browser/CognitoIdentity';
const cognitoIdentity = new AWS.CognitoIdentity({region: 'region'})
cognitoIdentity.createIdentityPool(params, (err, data) => {
    //do something
})

```

### Troubleshooting 

When the service returns an exception, inpecting the exceptions is always helpful. You can not only access the exception information but also response metadata(i.e request id).

```javascript
try {
    const data = await cognitoIdentity.send(createIdentityPoolCommand);
    // do something
} catch(error) {
    const metadata = error.$metadata;
    console.log(
`requestId: ${metadata.requestId}
cfId: ${metadata.cfId}
extendedRequestId: ${metadata.extendedRequestId}`
    );
/*
The keys within exceptions are also parsed, you can access them by specifying exception names like below:
    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 and have limited bandwidth to address them.

 * Ask a question on [StackOverflow](https://stackoverflow.com/) and tag it with `aws-sdk-js`
 * Come join the AWS JavaScript community on [gitter](https://gitter.im/aws/aws-sdk-js-v3)
 * If it turns out that you may have found a bug, please [open an issue](https://github.com/aws/aws-sdk-js-v3/issues)

## Contributing
 
This client code is generated automatically. Any modifications will be overwritten the next time the `@aws-sdk/@aws-sdk/client-cognito-identity-browser' package is updated. To contribute to SDK you can checkout our [code generator package][].

## License

This SDK is distributed under the
[Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0),
see LICENSE for more information.

[code generator package]: https://github.com/aws/aws-sdk-js-v3/tree/master/packages/service-types-generator

[API reference]: https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/

---
_Source: https://npm.io/package/@aws-sdk/client-cognito-identity-browser · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
