Passport - SteemConnect 1.1.0 + Bug Fixes + BONUS Mongo Example

in #dev7 years ago (edited)

Passport-SteemConnect

A SteemConnect authentication strategy for Passport.


Screen Shot 2018-04-25 at 11.32.27 PM.png

var mongoose              = require("mongoose"),
    passportLocalMongoose = require("passport-local-mongoose")

var UserSchema = new mongoose.Schema({
    _id: Number,
    username: String,
    password: String,
    accessToken: String,
    refreshToken: String,
    profile: Object
});

UserSchema.plugin(passportLocalMongoose);


module.exports = mongoose.model("User", UserSchema);

passport.use(
  new Strategy(
    {
      authorizationURL: `https://steemconnect.com/oauth2/authorize`,
      tokenURL: `https://steemconnect.com/api/oauth2/token`,
      clientID: process.env.clientID,
     clientSecret: process.env.clientSecret,
      callbackURL: `http://localhost:3000/auth/oauth/oauth2/callback`,
      scope: ["vote", "comment"]
    },
    function(accessToken, refreshToken, profile, cb) {
      let userInfo = {
        _id: profile.id,
        username: profile.username,
        password: null,
        accessToken: accessToken,
        refreshToken: refreshToken,
        profile: profile
      };

      User.update({ _id: userInfo._id }, userInfo, { upsert: true }, function(
        err,
        result
      ) {
        err ? console.log(err) : cb(null, profile);
      });
    }
  )
);

passport.serializeUser(function(user, cb) {
  cb(null, user.id);
});

passport.deserializeUser(function(obj, cb) {
  User.findOne({ _id: obj }, (err, user) => {
    err ? console.log(err) : cb(null, user.profile);
  });
});
/*
mongoose.connect("mongodb://localhost/db");
*/

2.png

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

To use this passport Strategy just install passport-steemconnect

Install

$ npm i passport-steemconnect --save

1.png
Passport Strategy: https://github.com/SMWARREN/Passport-SteemConnect
Passport Strategy With Example : https://github.com/SMWARREN/SteemConnect-Next-Auth-Micro-Service

Sort:  

Congratulations @mildfun! You received a personal award!

Happy Birthday! - You are on the Steem blockchain for 2 years!

You can view your badges on your Steem Board and compare to others on the Steem Ranking

Vote for @Steemitboard as a witness to get one more award and increased upvotes!

Coin Marketplace

STEEM 0.22
TRX 0.21
JST 0.035
BTC 91569.43
ETH 3174.28
USDT 1.00
SBD 3.07