Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
twee-passport-extension
Advanced tools
Readme
Passport Extension for Twee.IO Framework - Modular Framework for Node.js and io.js based on Express.js.
Supports
Strategy
variants.Also supports BasicStrategy
and DigestStrategy
for passport-http
.
All the other strategies could be added in future or added in middleware functions.
Before Installing into application twee-passport-extension
emmits event:
// ...
twee.emit('twee-passport-extension.strategiesInstalled'); // <- HERE
// Initializing Passport
app.use(passport.initialize());
app.use(passport.session());
// ...
So you can subscribe to this event and wait until twee-passport-extension
will install it's strategies. And add your specific strategies to application.
Just like:
twee.once('twee-passport-extension.strategiesInstalled', function(){
// Add your custom strategies here
})
To install extension use this command:
npm install twee-passport-extension --save
Also if you need to support some passport strategies just add them in package.json
too by editing package.json
of your application:
"dependencies": {
"twee-passport-extension": "*",
"express-session": "*", // This is for storing returned data into session
"passport": "*",
"passport-twitter": "*",
"passport-facebook": "*",
"passport-google": "*",
"passport-linkedin": "*",
"passport-http": "*",
}
Turning extension ON
in application/configs/twee.js
:
module.exports = {
"extensions": {
"Passport": {
"module": "twee-passport-extension"
}
}
};
Here is typical config regarding using this extension application/configs/twee.js
:
module.exports = {
"extensions": {
"i18n": {
"module": "twee-i18n-extension",
"dependencies": {
"Cookies": {
"module": "twee-cookies-extension"
}
}
},
"Passport": {
"module": "twee-passport-extension"
},
"HTML Compressor": {
dependencies: {
"Session": {
"disabled": true
}
}
}
},
"options": {
"errorPages": {
"404": {
"viewTemplate": __dirname + "/../views/common/pages/404.html"
}
}
},
"extension": {
// Here is our config setup
"twee-passport": {
// we can disable all the twee-passport here
"disabled": false,
// Redirects for twitter, google, facebook, linkedin etc
"redirects": {
"successRedirect": "/login",
"failureRedirect": "/login"
},
// Strategies list
"strategies": {
// Keys of strategies names should be lowercased and are used to initialize `passport.athenticate` method
"google": {
// Module in which our strategy exists
"module": "passport-google",
// We can disable this specific strategy
"disabled": false,
// If we need credentials they should be here
"credentials": {
"returnURL": "http://127.0.0.1:3000/auth/google/return",
"realm": "http://127.0.0.1:3000/",
"iis": "YOUR-UNIQUE-DEV-ID@developer.gserviceaccount.com"
},
// These urls are used for express app.all(urls.redirect, ...)
"urls": {
"redirect": "/auth/google",
"callback": "/auth/google/return"
},
// These options are used to pass them to `passport.authenticate` as second param
"options": {
"scope": "https://www.googleapis.com/auth/userinfo.email https://www.googleapis.com/auth/userinfo.profile"
}
},
"twitter": {
"module": "passport-twitter",
"disabled": false,
"credentials": {
"consumerKey": "YOUR-CONSUMER-KEY",
"consumerSecret": "YOUR-CONSUMER-SECRET",
"callbackURL": "http://127.0.0.1:3000/auth/twitter/callback/"
},
"urls": {
"redirect": "/auth/twitter",
"callback": "/auth/twitter/callback/*"
}
},
"facebook": {
"module": "passport-facebook",
"disabled": false,
"credentials": {
"clientID": "YOUR-CLIENT-ID",
"clientSecret": "YOUR-CLIENT-SECRET",
"callbackURL": "http://127.0.0.1:3000/auth/facebook/callback"
},
"urls": {
"redirect": "/auth/facebook",
"callback": "/auth/facebook/callback"
},
"options": {
"scope": "email"
}
},
"linkedin": {
"module": "passport-linkedin",
"disabled": false,
"credentials": {
"consumerKey": "YOUR-CONSUMER-KEY",
"consumerSecret": "YOUR-CONSUMER-SECRET",
"callbackURL": "http://127.0.0.1:3000/auth/linkedin/callback",
"profileFields": ["id", "first-name", "last-name", "email-address", "headline"]
},
"urls": {
"redirect": "/auth/linkedin",
"callback": "/auth/linkedin/callback"
},
"options": {
"scope": ["r_fullprofile", "r_emailaddress"]
}
},
// Here is digest supported strategy
"digest": {
"module": "passport-http",
"disabled": false,
"options": {
},
// The list of url patterns for Express.js to use this auth on
"authUrlPattern": ["/"]
},
// Basic strategy just like digest. It has little bit different callback (see below)
"basic": {
"module": "passport-http",
"disabled": false,
"options": {
},
"authUrlPattern": ["/bootstrap"]
}
}
}
}
};
Ok we have our correct configuration. What is next? You should know that you can subscribe to events to get fetched data in your controllers.
Lets see what kind of events we can have.
<a class="btn btn-primary" href="/auth/twitter">Twitter</a> |
<a class="btn btn-primary" href="/auth/facebook">Facebook</a> |
<a class="btn btn-primary" href="/auth/google">Google+</a> |
<a class="btn btn-primary" href="/auth/linkedin">LinkedIn</a>
That's all.
Lets assume we have AuthController
:
var session = require('express-session');
module.exports = function() {
/**
* Setting up passport for authenticating
*/
this.init = function () {
var self = this;
// Usual twitter, facebook and others callbacks with usual Strategy
twee.on('passport.Strategy.Callback', function(){
var data = twee.get('passport.Strategy.Data');
// all the data with tokens etc
// with done method are in arguments
session.user = data.arguments[2];
data.done();
});
// Here we can serialize user
twee.on('passport.serializeUser', function(){
//console.log('Serialize callback!');
//console.log(twee.get('passport.serializeUser'));
});
// We can access nonce here and check it
// this implementation is required for digest auth
twee.on('passport.Strategy.Digest.Params', function(){
var params = twee.get('passport.Strategy.Digest.Params');
console.log('Digest Params: ', params);
params.done(null, true);
});
// Digest callback will authenticate or not the user
twee.on('passport.Strategy.Digest.Callback', function(){
var data = twee.get('passport.Strategy.Data');
session.user = {username: 'admin', password: 'pw'};
return data.done(null, session.user, session.user.password);
});
// Basic callback will authenticate or not the user
twee.on('passport.Strategy.Basic.Callback', function(){
var data = twee.get('passport.Strategy.Data');
session.user = {username: 'admin', password: 'pw1'};
if (data.password != session.user.password
|| data.username != session.user.username) {
return data.done(null, false);
}
return data.done(null, session.user);
});
};
/**
* Signup action that renders signup form
* @param req
* @param res
*/
this.loginAction = function (req, res) {
var self = this;
res.render('Default/views/pages/Default/login', {
user: session.user
});
}
};
We also can subscribe to passport.deserializeUser
event to deserialize data.
And finally if we have twitter
key in configuration, then we can subscribe for specific twitter event: passport.Strategy.twitter
, for facebook
it will be passport.Strategy.facebook
etc.
You can check this example: https://github.com/tweeio/twee-examples/tree/master/passport
Here is how it looks like:
FAQs
Passport Extension for Twee.IO Framework - Modular Framework for Node.js based on Express.js
The npm package twee-passport-extension receives a total of 2 weekly downloads. As such, twee-passport-extension popularity was classified as not popular.
We found that twee-passport-extension demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.