npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@cumulus/oauth-client

v22.0.0

Published

A generic auth client

Readme

@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)

| Param | Type | Description | | --- | --- | --- | | params | Object | | | params.token | string | The access token for Authorization header | | [params.xRequestId] | string | a string to help identify the request |

Example

{
 "username": "janedoe",
 "given_name": "Jane",
 "family_name": "Doe",
 "study_area": "Atmospheric Composition",
 "organization": "NASA",
 "email": "[email protected]"
}

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)

| Param | Type | Description | | --- | --- | --- | | params | Object | | | params.token | string | The access token for Authorization header | | params.username | string | The uid of the registered user | | [params.xRequestId] | string | a 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": "[email protected]",
 "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

| 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 |

OAuthClient

A generic authorization client

Kind: global class

new OAuthClient(params)

| Param | Type | Description | | --- | --- | --- | | params | Object | | | params.clientId | string | see example | | params.clientPassword | string | see example | | params.loginUrl | string | see example | | params.redirectUri | string | see 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

| Param | Type | Description | | --- | --- | --- | | [state] | string | an 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

| Param | Type | Description | | --- | --- | --- | | authorizationCode | string | an 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

| Param | Type | Description | | --- | --- | --- | | params | Object | | | params.path | string | the URL for the request | | params.form | Object | the body of the POST request | | [params.headers] | Object | Optional 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

| Param | Type | Description | | --- | --- | --- | | params | Object | | | params.path | string | the URL for the request | | params.token | string | Auth bearer token for request | | [params.headers] | Object | Optional request headers | | [params.searchParams] | Object | Optional 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

| Param | Type | Description | | --- | --- | --- | | refreshToken | string | an 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