actionhero-oauth2-client
Advanced tools
Comparing version 0.1.0 to 1.0.0
@@ -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
1
6
1
1
37
0
2
70
76
- Removedrequest@>= 2.31.x
- Removedajv@6.12.6(transitive)
- Removedasn1@0.2.6(transitive)
- Removedassert-plus@1.0.0(transitive)
- Removedasynckit@0.4.0(transitive)
- Removedaws-sign2@0.7.0(transitive)
- Removedaws4@1.13.2(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedcombined-stream@1.0.8(transitive)
- Removedcore-util-is@1.0.2(transitive)
- Removeddashdash@1.14.1(transitive)
- Removeddelayed-stream@1.0.0(transitive)
- Removedecc-jsbn@0.1.2(transitive)
- Removedextend@3.0.2(transitive)
- Removedextsprintf@1.3.0(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-json-stable-stringify@2.1.0(transitive)
- Removedforever-agent@0.6.1(transitive)
- Removedform-data@2.3.3(transitive)
- Removedgetpass@0.1.7(transitive)
- Removedhar-schema@2.0.0(transitive)
- Removedhar-validator@5.1.5(transitive)
- Removedhttp-signature@1.2.0(transitive)
- Removedis-typedarray@1.0.0(transitive)
- Removedisstream@0.1.2(transitive)
- Removedjsbn@0.1.1(transitive)
- Removedjson-schema@0.4.0(transitive)
- Removedjson-schema-traverse@0.4.1(transitive)
- Removedjson-stringify-safe@5.0.1(transitive)
- Removedjsprim@1.4.2(transitive)
- Removedmime-db@1.52.0(transitive)
- Removedmime-types@2.1.35(transitive)
- Removedoauth-sign@0.9.0(transitive)
- Removedperformance-now@2.1.0(transitive)
- Removedpsl@1.15.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedrequest@2.88.2(transitive)
- Removedsafe-buffer@5.2.1(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedtough-cookie@2.5.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduri-js@4.4.1(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)