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 🙏

© 2024 – Pkg Stats / Ryan Hefner

oauth-token

v2.0.1

Published

Encode / decode data to the string access token

Downloads

38

Readme

oauth-token

Build Coverage Status

Instalation

$ npm install oauth-token

Usage

Configure
var options = {
  salt: 'some_random_string',
  // How long tokens will be valid since creation
  ttl: 86400,
  // Function for verifying validity of the application secret key
  checkAppSecret: function (userId, userSecret, cb) {
    // Return promise OR use callback
    return Promise.resolve(true)
  },
  // Function for verifying validity of the user secret key
  checkUserSecret: function (userId, userSecret, cb) {
    return Promise.resolve(true)
  },
  // Function for verifying the session existence
  checkSession: function (sessionId, cb) {
    return Promise.resolve(true)
  }
}

var OauthToken = require('oauth-token')(options)
Create token
var data = {
  appId: 'my_app',
  appSecret: '9iZp4FqiubL6',
  userId: '198623486', // userId is required and must be string
  userSecret: '1HMuXS5KBTWQ',
  session: 'QxBfjfUQsD66'
}

/**
 * Create OAuth token
 * uses underscore because of the OAuth2 convention
 *
 * {
 *   access_token: 'HUdefAxx2Sxknx2QffZso2mgsSAmFLZpPrqPNVduZKNkCRaCqgLjh3rDzu8xJkkGsyx3XX6UWyZ2Yy9a4sQaBwss5R4f5bLsUat7ky8f5m1EJeE3N266ofqaA',
 *   refresh_token: '8VzrgFaYVH9LjodbgwKfFxy1EFiVraty2HCcHtsqNxGMkHrm5BNvfpPzJM2EmRCb4QS5R5pcdp83pxRM6juou4nDwc8EkJzrMhtLJALsMZnjeFt6U',
 *   token_type: 'Bearer',
 *   issued: 1477775581,
 *   expires_in: 86400
 * }
 */

// returns Promise
OauthToken.create(data).then(function (oauthToken) {
})

// OR use callback
OauthToken.create(data, function (err, oauthToken) {
})
Decode token
var accessToken = 'HUdefAxx2Sxknx2QffZso2mgsSAmFLZpPrqPNVduZKNkCRaCqgLjh3rDzu8xJkkGsyx3XX6UWyZ2Yy9a4sQaBwss5R4f5bLsUat7ky8f5m1EJeE3N266ofqaA'

/**
 * Decode access_token to data
 *
 * {
 *   appId: 'my_app',
 *   appSecret: '9iZp4FqiubL6',
 *   userId: '198623486',
 *   userSecret: '1HMuXS5KBTWQ',
 *   session: 'QxBfjfUQsD66',
 *   issued: 1477775581,
 *   ttl: 86400
 * }
 *
 * checkAppSecret, checkUserSecret and checkSession
 * will be used for token validity verifying
 */

// returns Promise
OauthToken.decode(accessToken).then(function (data) {
})

// OR use callback
OauthToken.decode(accessToken, function (err, data) {
})
Refresh token
var refreshToken = '8VzrgFaYVH9LjodbgwKfFxy1EFiVraty2HCcHtsqNxGMkHrm5BNvfpPzJM2EmRCb4QS5R5pcdp83pxRM6juou4nDwc8EkJzrMhtLJALsMZnjeFt6U'

/**
 * Create new OAuth token by refresh_token
 * all original values will be preserved only 'issued' will set on now
 *
 * {
 *   access_token: 'HUdefAxx2Sxknx2QffZso2mgsSAmFLZpPrqPNVduZKNkCRaCqgLjh3rDzu8xJkkGsyx3XX6UWyZ2Yy9a4sQaBwswWVrC3NnMAdK7BZYmtFCHYaTbWTTSUWpvk',
 *   refresh_token: '8VzrgFaYVH9LjodbgwKfFxy1EFiVraty2HCcHtsqNxGMkHrm5BNvfpPzJM2EmRCb4QS5R5pcdp83pxRM6juou4nDwc8EkJzrMhtLJALsMZnjeFt6U',
 *   token_type: 'Bearer',
 *   issued: 1477776104,
 *   expires_in: 86400
 * }
 */

// returns Promise
OauthToken.refresh(refreshToken).then(function (oauthToken) {
})

// OR use callback
OauthToken.refresh(refreshToken, function (err, oauthToken) {
})

License

This tool is issued under the MIT license.