# @cumulus/earthdata-login-client

> A client for the Earthata Login service API

Latest version **9.0.1** (published 2021-05-07) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @cumulus/earthdata-login-client
pnpm add @cumulus/earthdata-login-client
yarn add @cumulus/earthdata-login-client
bun add @cumulus/earthdata-login-client
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; no vulnerabilities; high maintenance score; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 9.0.1 |
| Published | 2021-05-07 |
| First published | 2020-06-17 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=12.18.0 |
| Dependencies | 1 |
| Unpacked size | 29.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 305 |
| Author | Cumulus Authors |
| Maintainers | dopeters, npauzenga, cumuluspublisher, lfrederick, nemreid, kkelly51, nsidc_kovarik, flamingbear, jennyhliu |
| Keywords | Cumulus |

## Links

- npm: https://www.npmjs.com/package/@cumulus/earthdata-login-client
- Repository: https://github.com/nasa/cumulus
- Homepage: https://github.com/nasa/cumulus/tree/master/packages/earthdata-login-client#readme
- Issues: https://github.com/nasa/cumulus/issues
- npm.io page: https://npm.io/package/@cumulus/earthdata-login-client

## Dependencies (1)

- [got](https://npm.io/package/got.md) ^11.7.0

## Recent versions

- 9.0.1 (latest) — 2021-05-07
- 8.1.2 (release-v8.1.2) — 2021-08-04
- 8.1.1 (release-v8.1.1) — 2021-05-26
- 6.0.1 (release-v6.0.1) — 2021-03-25
- 2.0.8 (release-v2.0.8) — 2020-10-13
- 9.0.0 — 2021-05-05
- 8.1.0 — 2021-04-29
- 8.0.0 — 2021-04-12
- 7.2.0 — 2021-03-23
- 7.1.0 — 2021-03-12
- 7.0.0 — 2021-02-24
- 6.0.0 — 2021-02-16
- 5.0.1 — 2021-01-27
- 5.0.0 — 2021-01-12
- 4.0.0 — 2020-11-11
- … 11 more at https://npm.io/package/@cumulus/earthdata-login-client/versions

## README

# @cumulus/earthdata-login-client

Utilities for OAuth authentication using
[NASA Earthdata Login](https://urs.earthdata.nasa.gov/).

## Versioning

Cumulus uses a modified semantic versioning scheme and minor releases likely
include breaking changes.

Before upgrade, please read the Cumulus
[release notes](https://github.com/nasa/cumulus/releases) before upgraded.

It is strongly recommended you do not use `^` in your `package.json` to
automatically update to new minor versions. Instead, pin the version or use `~`
to automatically update to new patch versions.

## Installation

```bash
$ npm install @cumulus/earthdata-login-client
```

## Usage

```js
const { EarthdataLoginClient } = require('@cumulus/earthdata-login-client');

const client = new EarthdataLogin({
  clientId: 'my-client-id',
  clientPassword: 'my-client-password',
  earthdataLoginUrl: 'https://earthdata.login.nasa.gov',
  redirectUri: 'http://my-api.com'
});
```

## API

<a name="EarthdataLoginClient"></a>

## EarthdataLoginClient
A client for the Earthdata Login API

**Kind**: global class  

* [EarthdataLoginClient](#EarthdataLoginClient)
    * [new EarthdataLoginClient(params)](#new_EarthdataLoginClient_new)
    * [.getAuthorizationUrl([state])](#EarthdataLoginClient+getAuthorizationUrl) ⇒ <code>string</code>
    * [.getAccessToken(authorizationCode)](#EarthdataLoginClient+getAccessToken) ⇒ <code>Promise.&lt;Object&gt;</code>
    * [.refreshAccessToken(refreshToken)](#EarthdataLoginClient+refreshAccessToken) ⇒ <code>Promise.&lt;Object&gt;</code>
    * [.getTokenUsername(params)](#EarthdataLoginClient+getTokenUsername) ⇒ <code>Promise.&lt;string&gt;</code>

<a name="new_EarthdataLoginClient_new"></a>

### new EarthdataLoginClient(params)

| Param | Type | Description |
| --- | --- | --- |
| params | <code>Object</code> |  |
| params.clientId | <code>string</code> | see example |
| params.clientPassword | <code>string</code> | see example |
| params.earthdataLoginUrl | <code>string</code> | see example |
| params.redirectUri | <code>string</code> | see example |

**Example**  
```js
const oAuth2Provider = new EarthdataLogin({
  clientId: 'my-client-id',
  clientPassword: 'my-client-password',
  earthdataLoginUrl: 'https://earthdata.login.nasa.gov',
  redirectUri: 'http://my-api.com'
});
```
<a name="EarthdataLoginClient+getAuthorizationUrl"></a>

### earthdataLoginClient.getAuthorizationUrl([state]) ⇒ <code>string</code>
Get a URL of the Earthdata Login authorization endpoint

**Kind**: instance method of [<code>EarthdataLoginClient</code>](#EarthdataLoginClient)  
**Returns**: <code>string</code> - the Earthdata Login authorization URL  

| Param | Type | Description |
| --- | --- | --- |
| [state] | <code>string</code> | an optional state to pass to Earthdata Login |

<a name="EarthdataLoginClient+getAccessToken"></a>

### earthdataLoginClient.getAccessToken(authorizationCode) ⇒ <code>Promise.&lt;Object&gt;</code>
Given an authorization code, request an access token and associated
information from the Earthdata Login service.

Returns an object with the following properties:

- accessToken
- refreshToken
- username
- expirationTime (in seconds)

**Kind**: instance method of [<code>EarthdataLoginClient</code>](#EarthdataLoginClient)  
**Returns**: <code>Promise.&lt;Object&gt;</code> - access token information  

| Param | Type | Description |
| --- | --- | --- |
| authorizationCode | <code>string</code> | an OAuth2 authorization code |

<a name="EarthdataLoginClient+refreshAccessToken"></a>

### earthdataLoginClient.refreshAccessToken(refreshToken) ⇒ <code>Promise.&lt;Object&gt;</code>
Given a refresh token, request an access token and associated information
from the Earthdata Login service.

Returns an object with the following properties:

- accessToken
- refreshToken
- username
- expirationTime (in seconds)

**Kind**: instance method of [<code>EarthdataLoginClient</code>](#EarthdataLoginClient)  
**Returns**: <code>Promise.&lt;Object&gt;</code> - access token information  

| Param | Type | Description |
| --- | --- | --- |
| refreshToken | <code>string</code> | an OAuth2 refresh token |

<a name="EarthdataLoginClient+getTokenUsername"></a>

### earthdataLoginClient.getTokenUsername(params) ⇒ <code>Promise.&lt;string&gt;</code>
Query the Earthdata Login API for the UID associated with a token

**Kind**: instance method of [<code>EarthdataLoginClient</code>](#EarthdataLoginClient)  
**Returns**: <code>Promise.&lt;string&gt;</code> - the UID associated with the token  

| Param | Type | Description |
| --- | --- | --- |
| params | <code>Object</code> |  |
| params.onBehalfOf | <code>string</code> | the Earthdata Login client id of the   app requesting the username |
| params.token | <code>string</code> | the Earthdata Login token |
| [params.xRequestId] | <code>string</code> | a string to help identify the request   in the Earthdata Login logs |


## About Cumulus

Cumulus is a cloud-based data ingest, archive, distribution and management
prototype for NASA's future Earth science data streams.

[Cumulus Documentation](https://nasa.github.io/cumulus)

## Contributing

To make a contribution, please
[see our contributing guidelines](https://github.com/nasa/cumulus/blob/master/CONTRIBUTING.md).

---
Generated automatically using `npm run build-docs`

---
_Source: https://npm.io/package/@cumulus/earthdata-login-client · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
