@cumulus/earthdata-login-client
Utilities for OAuth authentication using NASA Earthdata Login.
Versioning
Cumulus uses a modified semantic versioning scheme and minor releases likely include breaking changes.
Before upgrade, please read the Cumulus release notes 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
$ npm install @cumulus/earthdata-login-client
Usage
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
EarthdataLoginClient
A client for the Earthdata Login API
Kind: global class
- EarthdataLoginClient
- new EarthdataLoginClient(params)
- .getAuthorizationUrl([state]) ⇒
string - .getAccessToken(authorizationCode) ⇒
Promise.<Object> - .refreshAccessToken(refreshToken) ⇒
Promise.<Object> - .getTokenUsername(params) ⇒
Promise.<string>
new EarthdataLoginClient(params)
| Param | Type | Description |
|---|---|---|
| params | Object |
|
| params.clientId | string |
see example |
| params.clientPassword | string |
see example |
| params.earthdataLoginUrl | string |
see example |
| params.redirectUri | string |
see example |
Example
const oAuth2Provider = new EarthdataLogin({
clientId: 'my-client-id',
clientPassword: 'my-client-password',
earthdataLoginUrl: 'https://earthdata.login.nasa.gov',
redirectUri: 'http://my-api.com'
});
earthdataLoginClient.getAuthorizationUrl([state]) ⇒ string
Get a URL of the Earthdata Login authorization endpoint
Kind: instance method of EarthdataLoginClient
Returns: string - the Earthdata Login authorization URL
| Param | Type | Description |
|---|---|---|
| [state] | string |
an optional state to pass to Earthdata Login |
earthdataLoginClient.getAccessToken(authorizationCode) ⇒ Promise.<Object>
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 EarthdataLoginClient
Returns: Promise.<Object> - access token information
| Param | Type | Description |
|---|---|---|
| authorizationCode | string |
an OAuth2 authorization code |
earthdataLoginClient.refreshAccessToken(refreshToken) ⇒ Promise.<Object>
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 EarthdataLoginClient
Returns: Promise.<Object> - access token information
| Param | Type | Description |
|---|---|---|
| refreshToken | string |
an OAuth2 refresh token |
earthdataLoginClient.getTokenUsername(params) ⇒ Promise.<string>
Query the Earthdata Login API for the UID associated with a token
Kind: instance method of EarthdataLoginClient
Returns: Promise.<string> - the UID associated with the token
| Param | Type | Description |
|---|---|---|
| params | Object |
|
| params.onBehalfOf | string |
the Earthdata Login client id of the app requesting the username |
| params.token | string |
the Earthdata Login token |
| [params.xRequestId] | string |
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.
Contributing
To make a contribution, please see our contributing guidelines.
Generated automatically using npm run build-docs