Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

passport-token-google

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

passport-token-google - npm Package Compare versions

Comparing version 0.1.4 to 0.1.5

32

lib/strategy.js

@@ -14,3 +14,3 @@ /**

*
* Applications must supply a `verify` callback which accepts an `accessToken`,
* Applications must supply a `verify` callback which accepts an `idToken`,
* `refreshToken` and service-specific `profile`, and then calls the `done`

@@ -32,3 +32,3 @@ * callback supplying a `user`, which should be set to `false` if the

* },
* function(accessToken, refreshToken, profile, done) {
* function(idToken, refreshToken, profile, done) {
* User.findOrCreate(..., function (err, user) {

@@ -75,7 +75,7 @@ * done(err, user);

var accessToken = req.body ? req.body.access_token || req.query.access_token || req.headers.access_token : req.headers.access_token || req.query.access_token;
var idToken = req.body ? req.body.id_token || req.query.id_token || req.headers.id_token : req.headers.id_token || req.query.id_token;
var refreshToken = req.body ? req.body.refresh_token || req.query.refresh_token || req.headers.refresh_token : req.headers.refresh_token || req.query.refresh_token;
self._loadUserProfile(accessToken, function(err, profile) {
self._loadUserProfile(idToken, function(err, profile) {
if (err) { return self.fail(err); };

@@ -90,5 +90,5 @@

if (self._passReqToCallback) {
self._verify(req, accessToken, refreshToken, profile, verified);
self._verify(req, idToken, refreshToken, profile, verified);
} else {
self._verify(accessToken, refreshToken, profile, verified);
self._verify(idToken, refreshToken, profile, verified);
}

@@ -108,8 +108,8 @@ });

*
* @param {String} accessToken
* @param {String} idToken
* @param {Function} done
* @api protected
*/
GoogleTokenStrategy.prototype.userProfile = function(accessToken, done) {
var profileUrl = 'https://www.googleapis.com/oauth2/v3/tokeninfo?access_token='+accessToken;
GoogleTokenStrategy.prototype.userProfile = function(idToken, done) {
var profileUrl = 'https://www.googleapis.com/oauth2/v3/tokeninfo?id_token='+idToken;
this._oauth2.get(profileUrl, null, function (err, body, res) {

@@ -124,4 +124,6 @@ if (err) { return done(new InternalOAuthError('failed to fetch user profile', err)); }

profile.displayName = json.name;
profile.name = { familyName: json.family_name,
givenName: json.given_name };
profile.name = {
familyName: json.family_name,
givenName: json.given_name
};
profile.emails = [{ value: json.email }];

@@ -143,11 +145,11 @@

*
* @param {String} accessToken
* @param {String} idToken
* @param {Function} done
* @api private
*/
GoogleTokenStrategy.prototype._loadUserProfile = function(accessToken, done) {
GoogleTokenStrategy.prototype._loadUserProfile = function(idToken, done) {
var self = this;
function loadIt() {
return self.userProfile(accessToken, done);
return self.userProfile(idToken, done);
}

@@ -160,3 +162,3 @@ function skipIt() {

// async
this._skipUserProfile(accessToken, function(err, skip) {
this._skipUserProfile(idToken, function(err, skip) {
if (err) { return done(err); }

@@ -163,0 +165,0 @@ if (!skip) { return loadIt(); }

{
"name": "passport-token-google",
"version": "0.1.4",
"version": "0.1.5",
"description": "Google token authentication strategy for Passport.",
"author": {
"name": "Satyarth Upadhyaya",
"email": "satyarth7a@hotmail.com"
"name": "Davide Polano",
"email": "davide@mdslab.org"
},

@@ -14,6 +14,6 @@ "scripts": {

"type": "git",
"url": "git://github.com/katastreet/passport-token-google.git"
"url": "git://github.com/davidep87/passport-token-google.git"
},
"bugs": {
"url": "http://github.com/katastreet/passport-token-google/issues"
"url": "http://github.com/davidep87/passport-token-google/issues"
},

@@ -20,0 +20,0 @@ "main": "./lib",

@@ -15,3 +15,3 @@ # Passport-Token-Google

$ npm install passport-token-google2
$ npm install --save passport-token-google

@@ -27,4 +27,12 @@ ## Usage

const GoogleStrategy = require('passport-token-google2').Strategy
const GoogleStrategy = require('passport-token-google').Strategy
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser((user, done) => {
done(null, user);
});
passport.use(new GoogleStrategy({

@@ -34,4 +42,4 @@ clientID: GOOGLE_CLIENT_ID,

},
function(accessToken, refreshToken, profile, done) {
fetchGoogleUser(profile, accessToken)
function(idToken, refreshToken, profile, done) {
fetchGoogleUser(profile, idToken)
.then((user) => done(null, user))

@@ -49,30 +57,11 @@ .catch((err) => {

router.get('/auth/google/token', passport.authenticate('google-token'), someFunction);
router.post('/auth/google/token', passport.authenticate('google-token'), someFunction);
GET request need to have `id_token` sent as `access_token` in either the query string or set as a header. If a POST is being preformed they can also be included in the body of the request.
GET request need to have `id_token` sent in either the query string or set as a header.
If a POST is being preformed they can also be included in the body of the request like:
#### Loopback 3.X support
Complaint with UserIdentity and User model of loopback
The module can be used to authenticate `id_token` sent by client side(android,ios or web) on the loopback as `access_token` in the callbackPath as GET argument.
Add this to providers.json as described in [tutorial!](https://loopback.io/doc/en/lb3/Third-party-login-using-Passport.html).
```
"google-login": {
"provider": "google",
"module": "passport-token-google2",
"clientID": "{google-client-id-1}",
"clientSecret": "{google-client-secret-1}",
"callbackPath": "/auth/google/token",
"scope": ["email", "profile"],
"failureFlash": true,
"json": true,
"session": false
`
const body = {
id_token: data.tokenId
}
```
`
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc