Git Product home page Git Product logo

parse-mapbox-token's Introduction

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

parse-mapbox-token's People

Contributors

bsushant-athena avatar davidtheclark avatar thibaudlopez avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

parse-mapbox-token's Issues

React Native compatibility

@nitaliano tried this (via mapbox-sdk-js) in React Native, and neither of the available parsing methods were available:

image

@nitaliano You can see that we're just trying to decode base64:

if (typeof window !== 'undefined' && window.atob) {
return JSON.parse(atob(rawPayload));
}
if (typeof Buffer !== 'undefined') {
return JSON.parse(new Buffer(rawPayload, 'base64').toString());
}
Do you know how we should do that so it works in React Native?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.