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

v0.1.1

Published

T-Moblie ID authentication strategy for Passport.

Downloads

5

Readme

passport-tmobileid

A Passport strategy for authenticating with T-Mobile ID using a method similar to OAuth 2.0 API.

This module lets you authenticate using T-Mobile ID in your Node.js applications. By plugging into Passport, T-Mobile ID authentication can be easily and unobtrusively integrated into any application or framework that supports Connect-style middleware, like Express.

Install

$ npm install passport-tmobileid

Usage

The T-Mobile ID authentication strategy authenticates users using their phone number or T-Mobile ID username. Developers wishing to utilize this plugin must first redirect their users to the T-Mobile authorization endpoint with the appropriate params.

var params = {'access_type': 'ONLINE',
  'redirect_uri': 'https://localhost:3000/auth/tmoid/callback',
  'scope': 'TMO_ID_profile,associated_lines,billing_information,entitlements',
  'client_id': TMOBILE_CLIENT_ID,
  'response_type' : 'code'};

res.redirect('https://auth.tmus.net/oauth2/v1/auth?' + qs.stringify(params));

Configure Strategy

The strategy requires four elements in order to properly process the authentication request, these are:

  1. redirect_uri - The callback URL local to your server
  2. tokenURL - The URL to the token request server
  3. clientID - Your client ID provied by T-Mobile
  4. clientSecret - Your client secret key provided by T-Mobile

Note: The strategy supports other standard passport arguments such as passReqToCallback.

var TMobileIDStrategy = require('passport-tmobileid').Strategy;

passport.use(new TMobileIDStrategy({
    redirect_uri : LOCAL_CALLBACK_URL,
    tokenURL : 'https://token.tmus.net/oauth2/v1/token',
    clientID : TMOBILE_CLIENT_ID,
    clientSecret : TMOBILE_CLIENT_SECRET,
    passReqToCallback : true //to get the req back from passport
},
function(req, token, expiry, id, done){
  if(err){return done(err);}
  if(!token){return done(null, false);} //No token could be retrieved from the server
  if(id) {
    //A T-Mobile access token has been provided
    User.findOne({'user.tmobileid' : id}, function(err,user){
      if(user) { //a user with this id has been found in your database
        user.tmobile.access_token = token; //add the tmobile access token to this user
        user.save(function(err){
          //handle the error
        }
        return done(null, user); //success
    });
  }
};  

Authenticate Requests

Use passport.authenticate(), specifying the 'tmoid' strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get('/auth/tmoid',
  res.redirect('https://uat.auth.tmus.net/oauth2/v1/auth?' + qs.stringify(params)));

app.get('/auth/tmoid/callback',
  passport.authenticate('tmoid', {
    failureRedirect: '/login',
    successRedirect: '/profile'
  }),
    function(req, res) {
      // Successful authentication, do nothing.
  });

Examples

For a complete, working example, refer to the example.

Credits

License

T-Mobile Terms and Conditions

(c) 2014 T-Mobile USA, Inc. All Rights Reserved.