Skip to content

Parse a Mapbox API token, in Node, browsers, or React Native

License

Notifications You must be signed in to change notification settings

mapbox/parse-mapbox-token

@mapbox/parse-mapbox-token

Build Status

Parse a Mapbox API token, in any JS environment, including Node, browser, and React Native.

Learn about Mapbox API tokens by reading Mapbox's API documentation.

Installation

npm install @mapbox/parse-mapbox-token

Usage

var parseToken = require('@mapbox/parse-mapbox-token');
var parsed = parseToken('MY_MAPBOX_TOKEN');
var ownerId = parsed.user;

Returns an object representing the parsed token. Properties vary depending on the type of token (public, secret, or temporary).

The following properties will always be present:

  • usage: pk, sk, or tk (public, secret, or temporary).
  • user: The ID of the token's owner.

The following properties may or may not be present:

  • authorization: Authorization associated with the owner's account.
  • created: Timestamp for the creation time of the token.
  • expires: Timestamp for the expiration time of the token.
  • lastLogin: Timestamp of the owner's last verified login.
  • scopes: Array of scopes available to the token.
  • client: OAuth client for which the token was granted.
  • impersonator: ID of the user impersonating the account owner.

The token's payload is parsed with base-64.

About

Parse a Mapbox API token, in Node, browsers, or React Native

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published