actionhero-oauth2-client
Advanced tools
Comparing version
@@ -1,8 +0,6 @@ | ||
var request = require('request'); | ||
module.exports = { | ||
name: 'oauth', | ||
version: 2, | ||
description: 'OAuth2', | ||
inputs: { required: [], optional: ['code', 'error', 'access_token'] }, | ||
description: 'OAuth2 Client', | ||
inputs: { required: ['code'], optional: ['error'] }, | ||
outputExample: {}, | ||
@@ -12,50 +10,16 @@ requireAuth: false, | ||
var code = connection.params.code; | ||
var access_token = connection.params.access_token; | ||
if(code){ | ||
api.oauth2.oauth.AuthCode.getToken({ | ||
code: code, | ||
redirect_uri: api.oauth2.redirect_url | ||
}, function (error, result) { | ||
if(error){ | ||
console.log('Access Token Error', error.message); | ||
//Access not granted... back to login?! or error page... | ||
connection.response.error = 'Bad Request' | ||
next(connection, true); | ||
}else{ | ||
access_token = api.oauth2.oauth.AccessToken.create(result).token.access_token; | ||
//save access token to connection.id | ||
api.cache.save(api.oauth2.action + ':token:' + access_token, connection.id); | ||
request.get(api.oauth2.site + api.oauth2.userPath + '?access_token=' + access_token, {json:true}, function(error, msg, result){ | ||
if(error){ | ||
connection.response.error = error; | ||
next(connection, false); | ||
}else{ | ||
api.cache.save(api.oauth2.action + ':connection:' + connection.id, {token:access_token, user:result.user}, null, function(){ | ||
var res = connection.rawConnection.res; | ||
res.writeHead(303, {Location: '/'}); | ||
res.end(); | ||
next(connection, false); | ||
}); | ||
} | ||
}); | ||
} | ||
}); | ||
}else{ | ||
if(access_token){ | ||
//destroy Access token | ||
api.cache.load(api.oauth2.action + ':token:' + access_token, function(err, connection_id){ | ||
api.cache.destroy(api.oauth2.action + ':connection:' + connection_id); | ||
api.cache.destroy(api.oauth2.action + ':token:' + access_token); | ||
}); | ||
} | ||
next(connection, true); | ||
} | ||
api.oauth2.oauth.AuthCode.getToken({ | ||
code: code, | ||
redirect_uri: api.oauth2.redirect_url | ||
}, function (error, result) { | ||
if(error){ | ||
api.oauth2.emit('unauthorized', api, connection, next); | ||
}else{ | ||
connection.params.access_token = api.oauth2.oauth.AccessToken.create(result).token.access_token; | ||
api.oauth2.emit('authorized', api, connection, next); | ||
} | ||
}); | ||
} | ||
} | ||
}; |
var OAuth2 = require('simple-oauth2'); | ||
var events = require('events'); | ||
var util = require('util'); | ||
@@ -12,12 +14,6 @@ var OAuth2Client = module.exports = function(config){ | ||
this.tokenPath = config.tokenPath || '/api/oauth/access_token'; | ||
this.userPath = config.userPath || '/api/user:info'; | ||
this.logoutPath = config.logoutPath || '/api/user:logout'; | ||
this.scope = config.scope | ''; | ||
this.action = config.action || 'oauth'; | ||
this.user_action = config.user_action || 'user'; | ||
this.logout_action = config.logout_action || 'logout'; | ||
this.client_site = config.client_site; | ||
this.oauth = new OAuth2({ | ||
@@ -32,2 +28,3 @@ clientID: this.id, | ||
this.initializer = function(api, next){ | ||
@@ -37,10 +34,7 @@ | ||
self.createOAuth2Action(api); | ||
self.createUserAction(api); | ||
self.createLogoutAction(api); | ||
self.createPreProcessor(api); | ||
self.createOAuth2Action(api); | ||
//to rebuild the required and optional params for the dummy action... | ||
api.params.buildPostVariables(); | ||
api.routes.routes.get.push({ path: 'user.js', action: self.user_action }); | ||
self.protocol = api.config.servers['web'].secure ? 'https' : 'http'; | ||
@@ -52,2 +46,5 @@ next(); | ||
util.inherits(OAuth2Client, events.EventEmitter); | ||
OAuth2Client.prototype.redirectToLogin = function(connection){ | ||
@@ -58,4 +55,4 @@ | ||
if(!self.redirect_url){ | ||
self.redirect_url = (api.config.servers['web'].secure ? 'https' : 'http') + "://" + req.headers.host + '/api/' + self.action; | ||
if(!this.redirect_url){ | ||
this.redirect_url = this.protocol + "://" + req.headers.host + '/api/' + this.action; | ||
} | ||
@@ -91,44 +88,2 @@ | ||
api.actions.actions[this.action][action.version] = action; | ||
}; | ||
OAuth2Client.prototype.createUserAction = function(api){ | ||
var action = require('./actions/user'); | ||
action.name = this.user_action; | ||
//oauth action to allow /api/oauth | ||
api.actions.versions[this.user_action] = [action.version]; | ||
api.actions.actions[this.user_action] = {}; | ||
api.actions.actions[this.user_action][action.version] = action; | ||
}; | ||
OAuth2Client.prototype.createLogoutAction = function(api){ | ||
var action = require('./actions/logout'); | ||
action.name = this.logout_action; | ||
//oauth action to allow /api/oauth | ||
api.actions.versions[this.logout_action] = [action.version]; | ||
api.actions.actions[this.logout_action] = {}; | ||
api.actions.actions[this.logout_action][action.version] = action; | ||
}; | ||
OAuth2Client.prototype.createPreProcessor = function(api){ | ||
var self = this; | ||
api.actions.preProcessors.push(function(connection, actionTemplate, next){ | ||
api.cache.load(self.action + ':connection:' + connection.id, function(err, value){ | ||
if(value){ | ||
connection.user = value.user; | ||
connection.access_token = value.token; | ||
} | ||
next(connection, true); | ||
}); | ||
}); | ||
}; |
{ | ||
"name": "actionhero-oauth2-client", | ||
"version": "0.1.0", | ||
"version": "1.0.0", | ||
"description": "ActionHero OAuth2 Client", | ||
"homepage": "", | ||
"author": { | ||
"name": "Philipp Waldmann" | ||
"keywords": ["actionhero", "oauth2", "client"], | ||
"author": "Philipp Waldmann <philipp.waldmann@s-team.at>", | ||
"repository": { | ||
"type": "git", | ||
"url": "git://github.com/s-team/actionhero-oauth2-client.git" | ||
}, | ||
"main": "./lib", | ||
"dependencies": { | ||
"simple-oauth2": ">= 0.1.x", | ||
"request": ">= 2.31.x" | ||
"simple-oauth2": ">= 0.1.x" | ||
}, | ||
"devDependencies": { | ||
} | ||
"devDependencies": {} | ||
} |
Copyleft License
License(Experimental) Copyleft license information was found.
Found 1 instance in 1 package
No website
QualityPackage does not have a website.
Found 1 instance in 1 package
Non-permissive License
License(Experimental) A license not known to be considered permissive was found.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
22261
192.41%1
-50%6
20%1
-50%1
-50%37
Infinity%0
-100%2
Infinity%70
-30%76
-58.24%- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed
- Removed