|
1 | | -# passport-google-oauth-token |
| 1 | +Passport's strategy for Javascript project. |
2 | 2 |
|
3 | | -[Passport](http://passportjs.org/) strategy for authenticating with [Google](http://www.google.com/) |
4 | | -access tokens using the OAuth 2.0 API. |
| 3 | +# Packages |
5 | 4 |
|
6 | | -This module is created based on [passport-facebook-token](https://github.com/drudge/passport-facebook-token) |
7 | | -and [passport-google-oauth2](https://github.com/jaredhanson/passport-google-oauth2). |
8 | | - |
9 | | -This module lets you authenticate using Google in your Node.js applications. |
10 | | -By plugging into Passport, Google authentication can be easily and |
11 | | -unobtrusively integrated into any application or framework that supports |
12 | | -[Connect](http://www.senchalabs.org/connect/)-style middleware, including |
13 | | -[Express](http://expressjs.com/). |
14 | | - |
15 | | -## Installation |
16 | | - |
17 | | - $ npm install passport-google-oauth-token |
18 | | - |
19 | | -## Usage |
20 | | - |
21 | | -### Configure Strategy |
22 | | - |
23 | | -The Google authentication strategy authenticates users using a Google |
24 | | -account and OAuth 2.0 tokens. The strategy requires a `verify` callback, which |
25 | | -accepts these credentials and calls `cb` providing a user, as well as |
26 | | -`options` specifying an app ID and app secret. |
27 | | - |
28 | | -```js |
29 | | -const GoogleOauthTokenStrategy = require('passport-google-oauth-token'); |
30 | | - |
31 | | -passport.use(new GoogleOauthTokenStrategy({ |
32 | | - clientID: GOOGLE_CLIENT_ID, |
33 | | - clientSecret: GOOGLE_CLIENT_SECRET, |
34 | | -}, (accessToken, refreshToken, profile, cb) => { |
35 | | - User.findOrCreate({ googleId: profile.id }, (error, user) => { |
36 | | - return done(error, user); |
37 | | - }); |
38 | | -})); |
39 | | -``` |
40 | | - |
41 | | -### Authenticate Requests |
42 | | - |
43 | | -Use `passport.authenticate()`, specifying the `'google-oauth-token'` strategy, to authenticate requests. |
44 | | - |
45 | | -```js |
46 | | -app.post('/auth/google/token', |
47 | | - passport.authenticate('google-oauth-token'), |
48 | | - (req, res) => { |
49 | | - // do something with req.user |
50 | | - res.send(req.user ? 200 : 401); |
51 | | - }, |
52 | | -); |
53 | | -``` |
54 | | - |
55 | | -### Client Requests |
56 | | - |
57 | | -Clients can send requests to routes that use passport-google-oauth-token authentication using `query parms`, `body`, or `HTTP headers`. Clients will need to transmit the `access_token` |
58 | | -and optionally the `refresh_token` that are received from google after login. |
59 | | - |
60 | | -## Options |
61 | | - |
62 | | -| Field | Description | Default Value | |
63 | | -| ------------------ | --------------------------------- | --------------------------------------------- | |
64 | | -| clientID | Google's client id | | |
65 | | -| clientSecret | Google's client secret | | |
66 | | -| tokenURL | Google's oauth2 token url | https://www.googleapis.com/oauth2/v4/token | |
67 | | -| profileURL | Google's scope profile url | https://www.googleapis.com/oauth2/v3/userinfo | |
68 | | -| authorizationURL | Google's oauth2 authorization url | https://accounts.google.com/o/oauth2/v2/auth | |
69 | | -| tokenURLVersion | Version of token url | v4 | |
70 | | -| userinfoURLVersion | Version of profile url | v3 | |
71 | | -| authURLVersion | Version of authorization url | v2 | |
72 | | - |
73 | | -## Profile Example |
74 | | - |
75 | | -```js |
76 | | -{ |
77 | | - provider: 'google', |
78 | | - id: '1234', |
79 | | - displayName: 'Alpha', |
80 | | - name: { |
81 | | - familyName: 'Lucifer', |
82 | | - givenName: 'Alpha', |
83 | | - }, |
84 | | - emails: [ |
85 | | - { |
86 | | - |
87 | | - verified: true, |
88 | | - }, |
89 | | - ], |
90 | | - photos: [ |
91 | | - { |
92 | | - value: 'https://google.com', |
93 | | - }, |
94 | | - ], |
95 | | - _json: {}, |
96 | | - _raw: {}, |
97 | | -} |
98 | | -``` |
99 | | - |
100 | | -## License |
101 | | - |
102 | | -The MIT License (MIT) |
103 | | - |
104 | | -Copyright (c) 2015 Nicholas Penree |
105 | | - |
106 | | -Permission is hereby granted, free of charge, to any person obtaining a copy |
107 | | -of this software and associated documentation files (the "Software"), to deal |
108 | | -in the Software without restriction, including without limitation the rights |
109 | | -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
110 | | -copies of the Software, and to permit persons to whom the Software is |
111 | | -furnished to do so, subject to the following conditions: |
112 | | - |
113 | | -The above copyright notice and this permission notice shall be included in all |
114 | | -copies or substantial portions of the Software. |
115 | | - |
116 | | -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
117 | | -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
118 | | -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
119 | | -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
120 | | -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
121 | | -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
122 | | -SOFTWARE. |
| 5 | +- [passport-google-oauth-token](packages/passport-google-oauth-token/README.md) |
0 commit comments