Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
giorgosavgeris committed May 21, 2020
1 parent 2e26f3b commit 8090820
Show file tree
Hide file tree
Showing 7 changed files with 236 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
.DS_Store
44 changes: 44 additions & 0 deletions README.md
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.
5 changes: 5 additions & 0 deletions lib/index.js
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;
29 changes: 29 additions & 0 deletions lib/profile.js
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;
};
81 changes: 81 additions & 0 deletions lib/strategy.js
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;
45 changes: 45 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions package.json
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"
}
}

0 comments on commit 8090820

Please sign in to comment.