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

passport-bitbucket-token

v1.0.0

Published

Passport strategy for authenticating with Bitbucket access tokens using the OAuth 2.0 API.

Downloads

13

Readme

passport-bitbucket-token

NPM

Build Status Coverage Status Dependency Status Code Climate npm version License

Passport strategy for authenticating with Bitbucket access tokens using the OAuth 2.0 API.

Library is inspired by passport-facebook-token.

Installation

npm install passport-bitbucket-token

Usage

Configure Strategy

The Bitbucket authentication strategy authenticate users using Bitbucket account and OAuthe 2 tokens. The strategy requires two parameters: options and verify callback. options are used to configure strategy. verify callback is function that accepts 4 arguments: accessToken, refreshToken, profile, done. profile is parsed Bitbucket profile. done is method which is called with user when verify method is finished.

var BitbucketTokenStrategy = require('passport-bitbucket-token');

passport.use(new BitbucketTokenStrategy({
      clientID: 'app-id',
      clientSecret: 'client-secret'
    },
    function (accessToken, refreshToken, profile, done) {
      User.upsertUser(accessToken, refreshToken, profile, function(err, user) {
        return done(err, user);
      });
    }));

Options

  • apiVersion - Which version of Bitbucket API user want to use. Allowed values are 1.0 or 2.0.
  • accessTokenField - Name of HTTP header, body field or query parameter where access token is stored in request
  • refreshTokenField - Name of HTTP header, body field or query parameter where refresh token is stored in request
  • passReqToCallback - Should verify function received as first parameter req object
  • profileWithEmail - If true library will try to load profile with all emails that are associated with profile. email is scope that is required. If nothing is selected emails will not be loaded.

Authenticate User

router.route('/auth/bitbucket')
  .post(passport.authenticate('bitbucket-token'), function(req, res, next) {
    if (!req.user) {
      return res.send(401, 'User Not Authenticated');
    }

    res.send(200);
  });

Client Requests

Sending access_token as a Query parameter

GET /auth/bitbucket?access_token=<TOKEN>

Sending access token as an HTTP header

GET /auth/bitbucket HTTP/1.1
Host: example.com
Authorization: Bearer base64_access_token_string

Sending access token as an HTTP body

POST /auth/bitbucket HTTP/1.1
Host: example.com

access_token=base64_access_token_string

Profile examples

In this section we will show examples of parsed profile that are returned to verify callback.

Bitbucket API v1.0

{ 
  provider: 'bitbucket',
  id: 'john_doe',
  username: 'john_doe',
  name: { first_name: 'John', last_name: 'Doe' },
  emails: [{value: '[email protected]', primary: true, verified: true}]
  avatar: 'https://bitbucket.org/account/john_doe/avatar/32/?ts=1492462087',
  _raw: 'raw json object from Bitbucket server',
  _json: 
   { 
     'parsed json object from server'
   }
}

Bitbucket API v2.0

{ 
  provider: 'bitbucket',
  id: 'john_doe',
  username: 'john_doe',
  display_name: 'John Doe',
  emails: [{value: '[email protected]', primary: true, verified: true}]
  avatar: 'https://bitbucket.org/account/john_doe/avatar/32/?ts=1492462087',
  _raw: 'raw json object from Bitbucket server',
  _json: 
   { 
     'parsed json object from server'
   }
}

Examples

Example of server application can be found here.

Full example of React.js + Node.js/Express.js can be found here.

License

passport-bitbucket-token is released under MIT License.