Skip to content

Commit

Permalink
Google Plus and linting changes
Browse files Browse the repository at this point in the history
* Re-forked from https://github.com/jaredhanson/passport-google-oauth2
@rwky
* Switched to google openid login as default for profile information
@rwky @MarshallOfSound @gtebbutt
* Removed google plus support since it's being shutdown @rwky
* Added eslint config @rwky
  • Loading branch information
rwky committed Jan 17, 2019
1 parent bf7b576 commit 90bc5a4
Show file tree
Hide file tree
Showing 28 changed files with 2,019 additions and 853 deletions.
3 changes: 3 additions & 0 deletions .eslintignore
@@ -0,0 +1,3 @@
.git
coverage/
node_modules/
24 changes: 24 additions & 0 deletions .eslintrc.js
@@ -0,0 +1,24 @@
module.exports = {
env: {
// jest: true,
mocha: true,
node: true,
},
extends: [
'airbnb-base',
],
plugins: [
// 'jest'
],
rules: {
"comma-dangle": 0,
"no-underscore-dangle": 0,
"no-param-reassign": 0,
"prefer-destructuring": 0,
// 'jest/no-disabled-tests': [2],
// 'jest/no-focused-tests': [2],
// 'jest/no-identical-title': [2],
// 'jest/prefer-to-have-length': [2],
// 'jest/valid-expect': [2],
}
};
13 changes: 5 additions & 8 deletions .travis.yml
@@ -1,13 +1,9 @@
language: "node_js"
node_js:
- "5"
- "4"
- "3" # io.js
- "2" # io.js
- "1" # io.js
- "0.12"
- "0.10"
- "0.8"
- "6"
- "8"
- "10"
- "11"


before_install:
Expand All @@ -16,6 +12,7 @@ before_install:

script:
- "make test-cov"
- "npm run-script lint"

after_success:
- "make report-cov"
Expand Down
16 changes: 16 additions & 0 deletions CHANGELOG.md
@@ -0,0 +1,16 @@
# 1.0.0 (2019-01-17)

* Re-forked from https://github.com/jaredhanson/passport-google-oauth2 @rwky
* Switched to google openid login as default for profile information @rwky @MarshallOfSound @gtebbutt
* Removed google plus support since it's being shutdown @rwky
* Added eslint config @rwky

# 0.3.0 (2018-11-03)

* Added coverPhoto to profile information @phingage
* Updated npm deps @rwky

# 0.2.0 (2018-06-29)

* Updated travis to use node 6, 8 and 10 @rwky
* Updated README.md and package.json for passport-next org @rwky
1 change: 1 addition & 0 deletions LICENSE
@@ -1,5 +1,6 @@
The MIT License (MIT)

Copyright (c) 2019 Rowan Wookey
Copyright (c) 2012-2016 Jared Hanson

Permission is hereby granted, free of charge, to any person obtaining a copy of
Expand Down
70 changes: 10 additions & 60 deletions README.md
@@ -1,38 +1,23 @@
# passport-google-oauth20

[Passport](http://passportjs.org/) strategy for authenticating with [Google](http://www.google.com/)
using the OAuth 2.0 API.

This module lets you authenticate using Google in your Node.js applications.
By plugging into Passport, Google authentication can be easily and
unobtrusively integrated into any application or framework that supports
[Connect](http://www.senchalabs.org/connect/)-style middleware, including
[Express](http://expressjs.com/).

---

<p align="center"><a href="http://www.tkqlhce.com/click-8907558-13433666" target="_top">1Password, the only password manager you should trust.</a> Industry-leading security and award winning design.</p>

---

Status:
[![Build](https://img.shields.io/travis/jaredhanson/passport-google-oauth2.svg)](https://travis-ci.org/jaredhanson/passport-google-oauth2)
[![Coverage](https://img.shields.io/coveralls/jaredhanson/passport-google-oauth2.svg)](https://coveralls.io/r/jaredhanson/passport-google-oauth2)
[![Quality](https://img.shields.io/codeclimate/github/jaredhanson/passport-google-oauth2.svg?label=quality)](https://codeclimate.com/github/jaredhanson/passport-google-oauth2)
[![Dependencies](https://img.shields.io/david/jaredhanson/passport-google-oauth2.svg)](https://david-dm.org/jaredhanson/passport-google-oauth2)
# Passport strategy for Google OAuth 2.0

[![NPM version](https://img.shields.io/npm/v/@passport-next/passport-google-oauth2.svg)](https://www.npmjs.com/package/@passport-next/passport-google-oauth2)
[![Build Status](https://travis-ci.org/passport-next/passport-google-oauth2.svg?branch=master)](https://travis-ci.org/passport-next/passport-google-oauth2)
[![Coverage Status](https://coveralls.io/repos/github/passport-next/passport-google-oauth2/badge.svg?branch=master)](https://coveralls.io/github/passport-next/passport-google-oauth2?branch=master)
[![Maintainability](https://api.codeclimate.com/v1/badges/7c817d8118420a47390a/maintainability)](https://codeclimate.com/github/passport-next/passport-google-oauth2/maintainability)
[![Dependencies](https://david-dm.org/passport-next/passport-google-oauth2.png)](https://david-dm.org/passport-next/passport-google-oauth2)
<!--[![SAST](https://gitlab.com/passport-next/passport-google-oauth2/badges/master/build.svg)](https://gitlab.com/passport-next/passport-google-oauth2/badges/master/build.svg)-->

## Install

```bash
$ npm install passport-google-oauth20
$ npm install @passport-next/passport-google-oauth2
```

## Usage

#### Create an Application

Before using `passport-google-oauth20`, you must register an application with
Before using `@passport-next/passport-google-oauth2`, you must register an application with
Google. If you have not already done so, a new project can be created in the
[Google Developers Console](https://console.developers.google.com/).
Your application will be issued a client ID and client secret, which need to be
Expand All @@ -50,7 +35,7 @@ Google profile. The `verify` callback must call `cb` providing a user to
complete authentication.

```javascript
var GoogleStrategy = require('passport-google-oauth20').Strategy;
var GoogleStrategy = require('@passport-next/passport-google-oauth2').Strategy;

passport.use(new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
Expand Down Expand Up @@ -84,28 +69,6 @@ app.get('/auth/google/callback',
res.redirect('/');
});
```

#### Google Plus API Deprecation

The default for `passport-google-oauth2` is to use the Google+ People API to
get the profile information for the user signing in. With this API being
removed in early 2019 you should look towards using the OAuth 2 User Info
endpoint instead. You can switch to this endpoint using this configuration
option.

```javascript
new GoogleStrategy({
clientID: GOOGLE_CLIENT_ID,
clientSecret: GOOGLE_CLIENT_SECRET,
callbackURL: "http://www.example.com/auth/google/callback",
// This option tells the strategy to use the userinfo endpoint instead
userProfileURL: "https://www.googleapis.com/oauth2/v3/userinfo",
}
```
The structure of the `profile` object will be the same but you may get
less profile information than you did before.
## Examples

Developers using the popular [Express](http://expressjs.com/) web framework can
Expand All @@ -114,16 +77,3 @@ as a starting point for their own web applications. The example shows how to
authenticate users using Facebook. However, because both Facebook and Google
use OAuth 2.0, the code is similar. Simply replace references to Facebook with
corresponding references to Google.
## Sponsorship
Passport is open source software. Ongoing development is made possible by
generous contributions from [individuals and corporations](https://github.com/jaredhanson/passport/blob/master/SPONSORS.md).
To learn more about how you can help keep this project financially sustainable,
please visit Jared Hanson's page on [Patreon](https://www.patreon.com/jaredhanson).
## License
[The MIT License](http://opensource.org/licenses/MIT)
Copyright (c) 2012-2016 Jared Hanson <[http://jaredhanson.net/](http://jaredhanson.net/)>
25 changes: 0 additions & 25 deletions lib/errors/googleplusapierror.js

This file was deleted.

6 changes: 1 addition & 5 deletions lib/errors/userinfoerror.js
Expand Up @@ -8,15 +8,11 @@
*/
function UserInfoError(message, code) {
Error.call(this);
Error.captureStackTrace(this, arguments.callee);
Error.captureStackTrace(this, UserInfoError);
this.name = 'UserInfoError';
this.message = message;
this.code = code;
}

// Inherit from `Error`.
UserInfoError.prototype.__proto__ = Error.prototype;


// Expose constructor.
module.exports = UserInfoError;
9 changes: 3 additions & 6 deletions lib/index.js
@@ -1,9 +1,6 @@
// Load modules.
var Strategy = require('./strategy');
const Strategy = require('./strategy');

Strategy.Strategy = Strategy;

// Expose Strategy.
exports = module.exports = Strategy;

// Exports.
exports.Strategy = Strategy;
module.exports = Strategy;
47 changes: 0 additions & 47 deletions lib/profile/googleplus.js

This file was deleted.

21 changes: 12 additions & 9 deletions lib/profile/openid.js
Expand Up @@ -17,24 +17,27 @@
* @return {object}
* @access public
*/
exports.parse = function(json) {
if ('string' == typeof json) {
function parse(json) {
if (typeof json === 'string') {
json = JSON.parse(json);
}
var profile = {};

const profile = {};
profile.id = json.sub || json.id;
profile.displayName = json.name;
if (json.family_name || json.given_name) {
profile.name = { familyName: json.family_name,
givenName: 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 || json.verified_email } ];
profile.emails = [{ value: json.email, verified: json.email_verified || json.verified_email }];
}
if (json.picture) {
profile.photos = [{ value: json.picture }];
}

return profile;
};
}
exports.parse = parse;

0 comments on commit 90bc5a4

Please sign in to comment.