# cognito-agent

> Authenticate with AWS Cognito and retreive credentials to use in your environment

Latest version **1.0.1** (published 2021-07-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install cognito-agent
pnpm add cognito-agent
yarn add cognito-agent
bun add cognito-agent
```

Provides the command `cognito-agent`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2021-07-30 |
| First published | 2021-07-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 6.5 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Tom Gardiner |
| Maintainers | tgardiner |
| Keywords | aws, amplify, cognito, awscurl, sigv4 |

## Links

- npm: https://www.npmjs.com/package/cognito-agent
- Repository: https://github.com/tgardiner/cognito-agent
- Homepage: https://github.com/tgardiner/cognito-agent#readme
- Issues: https://github.com/tgardiner/cognito-agent/issues
- npm.io page: https://npm.io/package/cognito-agent

## Dependencies (3)

- [cli-ux](https://npm.io/package/cli-ux.md) ^5.6.3
- [aws-sdk](https://npm.io/package/aws-sdk.md) ^2.957.0
- [amazon-cognito-identity-js](https://npm.io/package/amazon-cognito-identity-js.md) ^5.0.6

## Alternatives

- [base64url](https://npm.io/package/base64url.md) — 6.1M weekly downloads
- [get-installed-path](https://npm.io/package/get-installed-path.md) — 502.9K weekly downloads
- [@uppy/url](https://npm.io/package/@uppy/url.md) — 185.8K weekly downloads
- [@d3fc/d3fc-shape](https://npm.io/package/@d3fc/d3fc-shape.md) — 16.2K weekly downloads
- [localizer](https://npm.io/package/localizer.md) — 226 weekly downloads

## Recent versions

- 1.0.1 (latest) — 2021-07-30
- 1.0.0 — 2021-07-30

## README

# cognito-agent
Authenticate with AWS Cognito and retreive credentials to use in your environment

## Usecase

Testing authenticated API Gateway endpoints can be hard.  cognito-agent can be paired with [awscurl](https://github.com/okigan/awscurl/) to test API Gateway endpoints that use IAM authorization.

Example:

```bash
tom@MacBook ~ curl https://alfgjvvi136.execute-api.us-east-1.amazonaws.com/dev/v1/pets
{"message":"Missing Authentication Token"}

tom@MacBook ~ eval "$(cognito-agent)"
tom@MacBook ~ awscurl https://alfgjvvi136.execute-api.us-east-1.amazonaws.com/dev/v1/pets
{ id: 1, name: max, type: dog}
```

## Installation

```bash
npm i -g cognito-agent
```

## Configuration

cognito-agent can only be configured using environment variables.  If any config is missing, you will be prompted at runtime to enter the missing values.

### Environment Variables

| Variable                      | Description                 |
| ----------------------------- | --------------------------- |
| COGNITO_AGENT_USERNAME        | Cognito User Pool Username  |
| COGNITO_AGENT_PASSWORD        | Cognito User Pool Password  |
| COGNITO_AGENT_USERPOOL_ID     | Cognito User Pool Id        |
| COGNITO_AGENT_CLIENT_ID       | Cogntio User Pool Client Id |
| COGNITO_AGENT_IDENTITYPOOL_ID | Cognito Identity Pool Id    |

### Cli prompts at runtime

cognito-agent will prompt for any variable not found at runtime.

For exampe, you may wish to provide the username/password on the cli interactively:

```bash
tom@MacBook ~ cognito-agent
Username: tom@example.org
Password: ********

AWS_DEFAULT_REGION=us-east-1; export AWS_DEFAULT_REGION;
AWS_ACCESS_KEY_ID=ASIAZV...; export AWS_ACCESS_KEY_ID;
AWS_SECRET_ACCESS_KEY=hIrXEJI13k...; export AWS_SECRET_ACCESS_KEY;
AWS_SESSION_TOKEN=IQoJb3JpZ...; export AWS_SESSION_TOKEN;
```

## How it works

cognito-agent will log-in to the Cognito User Pool and then request a set of temporary credentials from the Cognito Identity Pool.  It spits out these credentials ready to be exported, much like ssh-agent.  You should use `eval "${cognito-agent}"` to avoid having the credentials appear in bash history and instead have them persisted into the environment ready to be used with subsequent commands, (either with `awscurl` or the normal `aws` cli).

---
_Source: https://npm.io/package/cognito-agent · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
