passport-google-oauth-token
Advanced tools
Comparing version 1.0.4 to 1.0.5
@@ -1,62 +0,3 @@ | ||
import * as express from 'express'; | ||
import * as passport from 'passport'; | ||
declare namespace PassportGoogleOauthToken { | ||
interface StrategyStatic { | ||
new(options: StrategyOptionsWithRequest, verify: VerifyFunctionWithRequest): StrategyInstance; | ||
new(options: StrategyOptions, verify: VerifyFunction): StrategyInstance; | ||
} | ||
interface StrategyInstance { | ||
name: string; | ||
authenticate: (req: express.Request, options?: any) => void; | ||
} | ||
interface ValueObject { | ||
value: string; | ||
} | ||
interface Profile extends passport.Profile { | ||
id: string; | ||
username?: string; | ||
name?: { | ||
givenName: string; | ||
middleName?: string; | ||
familyName: string; | ||
}; | ||
photos: ValueObject[]; | ||
emails: { | ||
value: string; | ||
verified: boolean; | ||
}[]; | ||
displayName: string; | ||
_raw: string; | ||
_json: any; | ||
} | ||
interface StrategyOptions { | ||
clientID: string; | ||
tokenURL?: string; | ||
profileURL?: string; | ||
clientSecret: string; | ||
authURLVersion?: string; | ||
tokenURLVersion?: string; | ||
authorizationURL?: string; | ||
userinfoURLVersion?: string; | ||
} | ||
interface StrategyOptionsWithRequest extends StrategyOptions { | ||
passReqToCallback: true; | ||
} | ||
type VerifyCallback = (error: any, user?: any, info?: any) => void; | ||
type VerifyFunction = (accessToken: string, refreshToken: string, profile: Profile, cb: VerifyCallback) => void; | ||
type VerifyFunctionWithRequest = (req: express.Request, accessToken: string, refreshToken: string, profile: Profile, cb: VerifyCallback) => void; | ||
} | ||
declare const PassportGoogleOauthToken: PassportGoogleOauthToken.StrategyStatic; | ||
export = PassportGoogleOauthToken; | ||
import GoogleOauthTokenStrategy from './Strategy'; | ||
export * from './interface'; | ||
export default GoogleOauthTokenStrategy; |
219
lib/index.js
@@ -1,213 +0,6 @@ | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } | ||
var OAuth2Strategy = require('passport-oauth2'); | ||
var InternalOAuthError = OAuth2Strategy.InternalOAuthError; | ||
/** | ||
* `GoogleOauthTokenStrategy` constructor. | ||
* | ||
* The Google authentication strategy authenticates requests by delegating to | ||
* Google using the OAuth 2.0 protocol. | ||
* | ||
* Applications must supply a `verify` callback which accepts an `accessToken`, | ||
* `refreshToken` and service-specific `profile`, and then calls the `cb` | ||
* callback supplying a `user`, which should be set to `false` if the | ||
* credentials are not valid. If an exception occurred, `err` should be set. | ||
* | ||
* @param {Object} options | ||
* @param {Function} verify | ||
* @example | ||
* passport.use(new GoogleOauthTokenStrategy( | ||
* { | ||
* clientID: '123456789', | ||
* clientSecret: 'abcxyz', | ||
* }, | ||
* (accessToken, refreshToken, profile, cb) => { | ||
* User.findOrCreate({ googleId: profile.id }, cb); | ||
* } | ||
* ); | ||
*/ | ||
var GoogleOauthTokenStrategy = function (_OAuth2Strategy) { | ||
_inherits(GoogleOauthTokenStrategy, _OAuth2Strategy); | ||
function GoogleOauthTokenStrategy() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var verify = arguments[1]; | ||
_classCallCheck(this, GoogleOauthTokenStrategy); | ||
var authURLVersion = options.authURLVersion || 'v2'; | ||
var tokenURLVersion = options.tokenURLVersion || 'v4'; | ||
var userinfoURLVersion = options.userinfoURLVersion || 'v3'; | ||
options.tokenURL = options.tokenURL || 'https://www.googleapis.com/oauth2/' + tokenURLVersion + '/token'; | ||
options.authorizationURL = options.authorizationURL || 'https://accounts.google.com/o/oauth2/' + authURLVersion + '/auth'; | ||
var _this = _possibleConstructorReturn(this, (GoogleOauthTokenStrategy.__proto__ || Object.getPrototypeOf(GoogleOauthTokenStrategy)).call(this, options, verify)); | ||
_this.name = 'google-oauth-token'; | ||
_this._profileURL = options.profileURL || 'https://www.googleapis.com/oauth2/' + userinfoURLVersion + '/userinfo'; | ||
return _this; | ||
} | ||
/** | ||
* Authenticate request by delegating to a service provider using OAuth 2.0. | ||
* @param {Object} req | ||
* @param {Object} options | ||
*/ | ||
_createClass(GoogleOauthTokenStrategy, [{ | ||
key: 'authenticate', | ||
value: function authenticate(req, _options) { | ||
var _this2 = this; | ||
var accessToken = this.lookup(req, 'access_token'); | ||
var refreshToken = this.lookup(req, 'refresh_token'); | ||
this._loadUserProfile(accessToken, function (error, profile) { | ||
if (error) { | ||
return _this2.error(error); | ||
} | ||
var verified = function verified(error, user, info) { | ||
if (error) { | ||
return _this2.error(error); | ||
} | ||
if (!user) { | ||
return _this2.fail(info); | ||
} | ||
return _this2.success(user, info); | ||
}; | ||
if (_this2._passReqToCallback) { | ||
_this2._verify(req, accessToken, refreshToken, profile, verified); | ||
} else { | ||
_this2._verify(accessToken, refreshToken, profile, verified); | ||
} | ||
}); | ||
} | ||
/** | ||
* Retrieve user profile from Google. | ||
* | ||
* This function constructs a normalized profile, with the following properties: | ||
* | ||
* - `provider` always set to `google` | ||
* - `id` the user's Google ID | ||
* - `username` the user's Google username | ||
* - `displayName` the user's full name | ||
* | ||
* @param {String} accessToken | ||
* @param {Function} done | ||
*/ | ||
}, { | ||
key: 'userProfile', | ||
value: function userProfile(accessToken, done) { | ||
this._oauth2.get(this._profileURL, accessToken, function (error, body, _res) { | ||
if (error) { | ||
return done(new InternalOAuthError('Failed to fetch user profile', error)); | ||
} | ||
try { | ||
var json = body; | ||
if (typeof body === 'string') { | ||
json = JSON.parse(body); | ||
} | ||
var profile = GoogleOauthTokenStrategy.parseProfile(json); | ||
profile._raw = body; | ||
done(null, profile); | ||
} catch (e) { | ||
done(e); | ||
} | ||
}); | ||
} | ||
/** | ||
* This method handles searhing the value of provided field in body, query, and header. | ||
* | ||
* @param {Object} req http request object | ||
* @param {String} field | ||
* @returns {String} field's value in body, query, or headers | ||
*/ | ||
}, { | ||
key: 'lookup', | ||
value: function lookup(req, field) { | ||
return req.body && req.body[field] || req.query && req.query[field] || req.headers && req.headers[field]; | ||
} | ||
/** | ||
* Parse profile. | ||
* | ||
* Parses user profiles as fetched from Google's OpenID Connect-compatible user | ||
* info endpoint. | ||
* | ||
* The amount of detail in the profile varies based on the scopes granted by the | ||
* user. The following scope values add additional data: | ||
* | ||
* `profile` - basic profile information | ||
* `email` - email address | ||
* | ||
* References: | ||
* - https://developers.google.com/identity/protocols/OpenIDConnect | ||
* | ||
* @param {object} json | ||
* @return {object} | ||
*/ | ||
}], [{ | ||
key: 'parseProfile', | ||
value: function parseProfile(json) { | ||
var profile = { | ||
provider: 'google', | ||
id: json.sub || json.id, | ||
displayName: json.name || '' | ||
}; | ||
if (json.family_name || json.given_name) { | ||
profile.name = { | ||
familyName: json.family_name, | ||
givenName: json.given_name | ||
}; | ||
} | ||
if (json.email) { | ||
profile.emails = [{ value: json.email, verified: json.email_verified }]; | ||
} | ||
if (json.picture) { | ||
profile.photos = [{ value: json.picture }]; | ||
} | ||
profile._json = json; | ||
return profile; | ||
} | ||
}]); | ||
return GoogleOauthTokenStrategy; | ||
}(OAuth2Strategy); | ||
exports.default = GoogleOauthTokenStrategy; | ||
module.exports = exports.default; | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const tslib_1 = require("tslib"); | ||
const Strategy_1 = tslib_1.__importDefault(require("./Strategy")); | ||
tslib_1.__exportStar(require("./interface"), exports); | ||
exports.default = Strategy_1.default; |
{ | ||
"name": "passport-google-oauth-token", | ||
"version": "1.0.4", | ||
"version": "1.0.5", | ||
"description": "Google access token authentication strategy for Passport", | ||
"author": "Alpha", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/zgid123/passport-google-oauth-token.git" | ||
}, | ||
"license": "MIT", | ||
"keywords": [ | ||
@@ -13,39 +19,24 @@ "passport", | ||
], | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"main": "lib/index.js", | ||
"scripts": { | ||
"compile": "rm -rf lib && babel src --out-dir lib && cp types/index.d.ts lib", | ||
"prepublish": "npm run compile", | ||
"test": "mocha --require babel-core/register test", | ||
"prepare": "husky install" | ||
}, | ||
"author": "Alpha", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:zgid123/passport-google-oauth-token.git" | ||
}, | ||
"license": "MIT", | ||
"types": "lib/index.d.ts", | ||
"dependencies": { | ||
"passport-oauth2": "^1.6.0" | ||
"passport-oauth2": "^1.7.0" | ||
}, | ||
"devDependencies": { | ||
"@types/express": "^4.17.13", | ||
"@types/passport": "^1.0.7", | ||
"@typescript-eslint/eslint-plugin": "^4.29.3", | ||
"@typescript-eslint/parser": "^4.29.3", | ||
"babel-cli": "^6.26.0", | ||
"babel-core": "^6.26.3", | ||
"babel-eslint": "^10.1.0", | ||
"babel-plugin-add-module-exports": "^1.0.4", | ||
"babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"babel-preset-es2015": "^6.24.1", | ||
"chai": "^4.3.4", | ||
"chai-passport-strategy": "^1.0.1", | ||
"eslint": "^7.32.0", | ||
"eslint-config-typescript": "^3.0.0", | ||
"husky": "^7.0.0", | ||
"lint-staged": "^11.1.2", | ||
"mocha": "^9.1.1", | ||
"sinon": "^11.1.2", | ||
"typescript": "^4.4.2" | ||
"@types/express": "^4.17.17", | ||
"@types/jest": "^29.4.0", | ||
"@types/oauth": "^0.9.1", | ||
"@types/passport-oauth2": "^1.4.12", | ||
"jest": "^29.5.0", | ||
"oauth": "^0.10.0", | ||
"ts-jest": "^29.0.5" | ||
}, | ||
"scripts": { | ||
"prepublish": "rm -rf lib && tsc", | ||
"test": "jest --config jest.config.json", | ||
"update-packages": "pnpm update -i -r --latest" | ||
} | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30413
7
16
733
1
Updatedpassport-oauth2@^1.7.0