Socket
Socket
Sign inDemoInstall

passport-trovo.js

Package Overview
Dependencies
7
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    passport-trovo.js

Passport strategies for authenticating with Trovo.live using OAuth 2.0.


Version published
Weekly downloads
3
Maintainers
1
Created
Weekly downloads
 

Readme

Source

passport-trovo.js

Build Status semantic-release

Downloads Downloads npm version License

dependencies dev dependencies

Code Climate Trovo Chat
PayPal

Trovo is a trademark or registered trademark of TLive LLC. in the U.S. and/or other countries. "passport-trovo.js" is not operated by, sponsored by, or affiliated with TLive LLC. in any way.

Passport strategies for authenticating with Trovo using OAuth 2.0 API.

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

Install

$ npm install passport-trovo.js

Usage of OAuth 2.0

Configure Strategy

The Trovo OAuth 2.0 authentication strategy authenticates users using a Trovo account and OAuth 2.0 tokens. The strategy requires a verify callback, which accepts these credentials and calls done providing a user, as well as options specifying a client ID, client secret, and callback URL.

var passport       = require("passport");
var trovoStrategy = require("passport-trovo.js").Strategy;

passport.use(new trovoStrategy({
    clientID: TROVO_CLIENT_ID,
    clientSecret: TROVO_CLIENT_SECRET,
    callbackURL: "http://127.0.0.1:3000/auth/trovo/callback",
    scope: ["guilds", "connections", "email"]
  },
  function(accessToken, refreshToken, profile, done) {
    //Handle Database Query Addition Here.
  }
));
Authenticate Requests

Use passport.authenticate(), specifying the "trovo.js" strategy, to authenticate requests.

For example, as route middleware in an Express application:

app.get("/auth/trovo", passport.authenticate("trovo.js"));
app.get("/auth/trovo/callback", passport.authenticate("trovo.js", { failureRedirect: "/" }), function(req, res) {
    // Successful authentication, redirect home.
    res.redirect("/");
});

The request to this route should include a GET or POST data with the keys access_token from Trovo.

GET /auth/trovo?access_token=<TOKEN>

Issues

If you receive a 401 Unauthorized error, it is most likely because you have wrong access token or not yet specified any application permissions. Once you refresh access token with new permissions, try to send this access token again.

Example

#!/bin/env node

require('dotenv').config();

var express = require('express');
var session = require('express-session');
var helmet = require('helmet');
var bodyParser = require('body-parser');

var passport = require('passport');
var refresh = require('passport-oauth2-refresh');
var _strategy = require('passport-trovo.js').Strategy;

var app = express();

app.use(session({
  key: process.env.SESSION_KEY,
  secret: process.env.SESSION_SECRET,
  resave: true,
  saveUninitialized: true,
  cookie: {
    secure: true
  }
}));

app.use(helmet());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

passport.serializeUser(function(u, d) {
  d(null, u);
});
passport.deserializeUser(function(u, d) {
  d(null, u);
});

var TrovoStrategy = new _strategy({
  clientID: process.env.TROVO_ID,
  clientSecret: process.env.TROVO_SECRET,
  callbackURL: "http://127.0.0.1:3000/auth/trovo/callback",
  scope: ["guilds", "connections", "email"]
}, function(accesstoken, refreshToken, profile, done) {
  console.log(profile);
  return done(null, profile);
});

passport.use(TrovoStrategy);
refresh.use(TrovoStrategy);

app.get('/', function(req, res) {
  if (!req.session.user) {
    res.redirect('/login');
  } else {
    res.send(`Hello ${req.session.user.username}`);
  }
});

app.get('/login', passport.authenticate('trovo.js'}));
app.get('/auth/trovo/callback', passport.authenticate('trovo.js', { failureRedirect: '/' }), function(req, res) {
  req.session.user = req.user;
  console.log(req.user);
  console.log(req.query);
  res.redirect('/');
});
app.listen(process.env.SITE_PORT, process.env.SITE_HOST, function() {
  console.log(`Express Started`);
});

Projected Maintained by: Randolph Aarseth(Bioblaze Payne)

Keywords

FAQs

Last updated on 02 Aug 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc