18.2.1 • Published 1 day ago

@cumulus/oauth-client v18.2.1

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
1 day ago

@cumulus/oauth-client

Utilities for OAuth authentication using NASA Earthdata Login and AWS Cognito.

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/oauth-client

Class Structure

This package contains a generic, parent class called OAuthClient. This class has a few common methods like oAuthClient.getAuthorizationUrl() which are used by all classes that inherit from OAuthClient.

The examples below document these common methods as well as methods specific to the child classes, e.g. cognitoClient.getUserInfo(accessToken).

Earthdata Login Usage Example

const { EarthdataLoginClient } = require('@cumulus/oauth-client');

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

Cognito Usage Example

const { CognitoClient } = require('@cumulus/oauth-client');

const client = new CognitoClient({
  clientId: 'my-client-id',
  clientPassword: 'my-client-password',
  loginUrl: 'https://auth.csdap.sit.earthdatacloud.nasa.gov/',
  redirectUri: 'http://my-api.com'
});

API

Classes

CognitoClient

A client for the Cognito API. Extents OAuthClient.

Kind: global class

cognitoClient.getUserInfo(params) ⇒ Promise.<Object>

Query the API for the user object associated with an access token.

Kind: instance method of CognitoClient
Returns: Promise.<Object> - The user object (see example)

ParamTypeDescription
paramsObject
params.tokenstringThe access token for Authorization header
params.xRequestIdstringa string to help identify the request

Example

{
 "username": "janedoe",
 "given_name": "Jane",
 "family_name": "Doe",
 "study_area": "Atmospheric Composition",
 "organization": "NASA",
 "email": "janedoe@example.com"
}

EarthdataLoginClient

A client for the Earthdata Login API. Extents OAuthClient.

Kind: global class

earthdataLoginClient.getUserInfo(params) ⇒ Promise.<Object>

Query the API for the user object associated with a user.

Kind: instance method of EarthdataLoginClient
Returns: Promise.<Object> - The user object (see example)

ParamTypeDescription
paramsObject
params.tokenstringThe access token for Authorization header
params.usernamestringThe uid of the registered user
params.xRequestIdstringa string to help identify the request

Example

{
 "uid": "janedoe",
 "first_name": "Jane",
 "last_name": "Doe",
 "registered_date": "15 Sep 2015 12:42:17PM",
 "email_address": "janedoe@example.com",
 "country": "United States",
 "affiliation": "Government",
 "authorized_date": "21 Apr 2016 01:13:28AM",
 "allow_auth_app_emails": true,
 "agreed_to_meris_eula": false,
 "agreed_to_sentinel_eula": false,
 "app_content": {
    "param1": "value1",
    "app_groups": {
        "test": {
           "param2": "value2"
         }
     }
 },
 "user_groups": [],
 "user_authorized_apps": 3
}

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

ParamTypeDescription
paramsObject
params.onBehalfOfstringthe Earthdata Login client id of the app requesting the username
params.tokenstringthe Earthdata Login token
params.xRequestIdstringa string to help identify the request in the Earthdata Login logs

OAuthClient

A generic authorization client

Kind: global class

new OAuthClient(params)

ParamTypeDescription
paramsObject
params.clientIdstringsee example
params.clientPasswordstringsee example
params.loginUrlstringsee example
params.redirectUristringsee example

Example

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

oAuthClient.getAuthorizationUrl(state) ⇒ string

Get a URL of the Login authorization endpoint

Kind: instance method of OAuthClient
Returns: string - the Login authorization URL

ParamTypeDescription
statestringan optional state to pass to login Client

oAuthClient.getAccessToken(authorizationCode) ⇒ Promise.<Object>

Given an authorization code, request an access token and associated information from the login service.

Returns an object with the following properties:

  • accessToken
  • refreshToken
  • username (optional, if "endpoint" is provided by client API response)
  • expirationTime (in seconds)

Kind: instance method of OAuthClient
Returns: Promise.<Object> - access token information

ParamTypeDescription
authorizationCodestringan OAuth2 authorization code

oAuthClient.postRequest(params) ⇒ CancelableRequest.<Response.<unknown>>

Make an HTTP POST request to the login service

Kind: instance method of OAuthClient
Returns: CancelableRequest.<Response.<unknown>> - The return of the POST call

ParamTypeDescription
paramsObject
params.pathstringthe URL for the request
params.formObjectthe body of the POST request
params.headersObjectOptional request headers

oAuthClient.getRequest(params) ⇒ CancelableRequest.<Response.<unknown>>

Make an HTTP GET request to the login service

Kind: instance method of OAuthClient
Returns: CancelableRequest.<Response.<unknown>> - The return of the GET call

ParamTypeDescription
paramsObject
params.pathstringthe URL for the request
params.tokenstringAuth bearer token for request
params.headersObjectOptional request headers
params.searchParamsObjectOptional search parameters

oAuthClient.refreshAccessToken(refreshToken) ⇒ Promise.<Object>

Given a refresh token, request an access token and associated information from the login service.

Returns an object with the following properties:

  • accessToken
  • refreshToken
  • username (optional, if "endpoint" is provided by client API response)
  • expirationTime (in seconds)

Kind: instance method of OAuthClient
Returns: Promise.<Object> - access token information

ParamTypeDescription
refreshTokenstringan OAuth2 refresh token

About Cumulus

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

Cumulus Documentation

Contributing

To make a contribution, please see our contributing guidelines.


Generated automatically using npm run build-docs

16.1.5

1 day ago

18.2.1

2 days ago

16.1.4

12 days ago

18.2.0

3 months ago

16.1.3

4 months ago

18.2.0-alpha.0

5 months ago

18.0.0

9 months ago

16.0.3-alpha.0

10 months ago

16.1.1

9 months ago

16.1.0

9 months ago

16.1.2

6 months ago

18.1.0

7 months ago

17.0.0

9 months ago

16.0.0

10 months ago

15.0.4

11 months ago

16.0.1-alpha.0

11 months ago

16.0.2-alpha.0

11 months ago

15.0.2

1 year ago

15.0.3

1 year ago

15.0.1

1 year ago

14.1.0

1 year ago

15.0.0

1 year ago

13.3.3-alpha.0

2 years ago

13.4.0

2 years ago

14.0.0

1 year ago

13.3.3-alpha.1

2 years ago

11.1.8

2 years ago

13.3.2

2 years ago

12.0.3

2 years ago

13.3.1

2 years ago

11.1.6

2 years ago

11.1.7

2 years ago

13.3.0

2 years ago

10.1.3

2 years ago

13.2.0

2 years ago

13.2.1

2 years ago

13.0.0

2 years ago

13.1.0

2 years ago

13.0.1

2 years ago

12.0.1

2 years ago

12.0.2

2 years ago

11.1.5

2 years ago

11.1.3

2 years ago

11.1.4

2 years ago

11.1.2

2 years ago

12.0.0

2 years ago

10.0.2

2 years ago

11.1.1

2 years ago

11.1.0

2 years ago

9.9.4

2 years ago

11.0.0

2 years ago

10.1.2

2 years ago

9.4.2

2 years ago

10.1.1

2 years ago

9.9.1

2 years ago

9.7.1

2 years ago

9.4.1

2 years ago

10.0.0

2 years ago

10.1.0

2 years ago

10.0.1

2 years ago

9.9.2

2 years ago

9.9.3

2 years ago

9.2.4

2 years ago

9.2.3

2 years ago

10.0.0-beta.0

2 years ago

9.9.0

3 years ago

9.8.0

3 years ago

9.7.0

3 years ago

9.6.0

3 years ago

9.5.0

3 years ago

9.4.0

3 years ago

9.2.2

3 years ago

9.2.1

3 years ago

9.3.0

3 years ago

9.2.0

3 years ago

9.1.0

3 years ago

9.0.1-alpha1

3 years ago

9.0.0-alpha1

3 years ago