-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e26f3b
commit 8090820
Showing
7 changed files
with
236 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
A simple [Passport](http://passportjs.org/) strategy for Zoom OAuth2. | ||
|
||
## Install | ||
|
||
npm install @giorgosavgeris/passport-zoom-oauth2 | ||
|
||
## Usage | ||
|
||
### Register the strategy | ||
|
||
```javascript | ||
var ZoomStrategy = require('@giorgosavgeris/passport-zoom-oauth2').Strategy; | ||
|
||
passport.use(new ZoomStrategy({ | ||
clientID: ZOOM_CLIENT_ID, | ||
clientSecret: ZOOM_CLIENT_SECRET, | ||
callbackURL: 'https://www.example.net/oauth/zoom/callback' | ||
}, | ||
function(accessToken, refreshToken, profile, done) { | ||
User.findOrCreate(..., function (err, user) { | ||
done(err, user); | ||
}); | ||
} | ||
)); | ||
``` | ||
|
||
### Authenticate requests | ||
|
||
```javascript | ||
app.get('/auth/zoom', passport.authenticate('zoom', { state: 'pass_state_here' })); | ||
|
||
app.get( | ||
'/auth/zoom/callback', | ||
passport.authenticate('zoom', { failureRedirect: '/login' }), | ||
function(req, res) { | ||
// Successful authentication | ||
res.redirect('/'); | ||
} | ||
); | ||
``` | ||
|
||
## License | ||
|
||
This project is licensed under the MIT license. See the [LICENSE](LICENSE) file for more info. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
var Strategy = require('./strategy'); | ||
|
||
exports = module.exports = Strategy; | ||
|
||
exports.Strategy = Strategy; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* Parse profile. | ||
* | ||
* @param {object|string} json | ||
* @return {object} | ||
* @access public | ||
*/ | ||
exports.parse = function(json) { | ||
if (typeof json === "string") { | ||
json = JSON.parse(json); | ||
} | ||
|
||
var profile = {}; | ||
|
||
profile.id = json.id; | ||
|
||
profile.displayName = json.first_name + " " + json.last_name; | ||
profile.name = { familyName: json.last_name, givenName: json.first_name }; | ||
|
||
if (json.email) { | ||
profile.emails = [{ value: json.email }]; | ||
} | ||
|
||
if (json.pic_url) { | ||
profile.photos = [{ value: json.pic_url }]; | ||
} | ||
|
||
return profile; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
var util = require("util"); | ||
var OAuth2Strategy = require("passport-oauth2"); | ||
var InternalOAuthError = require("passport-oauth2").InternalOAuthError; | ||
var Profile = require("./profile"); | ||
|
||
/** | ||
* `Strategy` constructor. | ||
* | ||
* Options: | ||
* - `clientID` Zoom application's App ID | ||
* - `clientSecret` Zoom application's App Secret | ||
* - `callbackURL` URL to which Zoom will redirect the user after granting authorization | ||
* | ||
* Examples: | ||
* | ||
* passport.use(new ZoomStrategy({ | ||
* clientID: ZOOM_CLIENT_ID, | ||
* clientSecret: ZOOM_CLIENT_SECRET, | ||
* callbackURL: 'https://www.example.net/oauth/zoom/callback' | ||
* }, | ||
* function(accessToken, refreshToken, profile, done) { | ||
* User.findOrCreate(..., function (err, user) { | ||
* done(err, user); | ||
* }); | ||
* } | ||
* )); | ||
* | ||
* @constructor | ||
* @param {object} options | ||
* @param {function} verify | ||
* @access public | ||
*/ | ||
*/ | ||
function Strategy(options, verify) { | ||
options = options || {}; | ||
|
||
options.authorizationURL = options.authorizationURL || "https://zoom.us/oauth/authorize"; | ||
options.tokenURL = options.tokenURL || "https://zoom.us/oauth/token"; | ||
|
||
OAuth2Strategy.call(this, options, verify); | ||
|
||
this.name = "zoom"; | ||
this.options = options; | ||
this._profileUrl = options.profileUrl || "https://api.zoom.us/v2/users/me"; | ||
} | ||
|
||
// Inherit from `OAuth2Strategy` | ||
util.inherits(Strategy, OAuth2Strategy); | ||
|
||
/** | ||
* Retrieve user profile from Zoom. | ||
* | ||
* @param {string} accessToken | ||
* @param {function} done | ||
* @access protected | ||
*/ | ||
Strategy.prototype.userProfile = function(accessToken, done) { | ||
this._oauth2.get(this._profileUrl, accessToken, function(err, body, res) { | ||
var json; | ||
|
||
if (err) { | ||
throw new InternalOAuthError("Failed to fetch user profile", err); | ||
} | ||
|
||
try { | ||
json = JSON.parse(body); | ||
} catch (ex) { | ||
return done(new Error("Failed to parse user profile")); | ||
} | ||
|
||
var profile = Profile.parse(json); | ||
|
||
profile.provider = "zoom"; | ||
profile._raw = body; | ||
profile._json = json; | ||
|
||
done(null, profile); | ||
}); | ||
}; | ||
|
||
module.exports = Strategy; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "@giorgosavgeris/passport-zoom-oauth2", | ||
"version": "1.0.0", | ||
"description": "Passport Strategy for Zoom OAuth 2.0", | ||
"main": "./lib", | ||
"directories": { | ||
"lib": "lib" | ||
}, | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/giorgosavgeris/passport-zoom-oauth2.git" | ||
}, | ||
"keywords": [ | ||
"passport", | ||
"zoom", | ||
"oauth2" | ||
], | ||
"author": "Giorgos Avgeris <giorgos.avgeris@hotmail.com>", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/giorgosavgeris/passport-zoom-oauth2/issues" | ||
}, | ||
"homepage": "https://github.com/giorgosavgeris/passport-zoom-oauth2#readme", | ||
"dependencies": { | ||
"passport-oauth2": "^1.5.0" | ||
} | ||
} |