@cgignite/ignite-auth
Advanced tools
Comparing version 1.0.5 to 1.0.7
module.exports = function(RED) | ||
{ | ||
const request = require('request'); | ||
const ClientOAuth2 = require('client-oauth2') | ||
const { ClientCredentials, ResourceOwnerPassword, AuthorizationCode } = require('simple-oauth2'); | ||
@@ -15,11 +14,14 @@ function oauth2Client(config) | ||
this.on('input', function (msg) { | ||
var authClient= new ClientOAuth2({ | ||
clientId: node.auth2Config.clientId, | ||
clientSecret: node.auth2Config.credentials.clientSecret, | ||
accessTokenUri: node.auth2Config.accessTokenUrl, | ||
authorizationUri: node.auth2Config.authUrl, | ||
redirectUri: node.auth2Config.redirectUrl, | ||
scopes: node.auth2Config.scope.split(',') | ||
}); | ||
var authConfig = { | ||
client: { | ||
id: node.auth2Config.clientId, | ||
secret: node.auth2Config.credentials.clientSecret | ||
}, | ||
auth: { | ||
//tokenHost: node.auth2Config.accessTokenUrl, | ||
tokenPath : ' ', | ||
//authorizeHost : node.auth2Config.authUrl, | ||
authorizePath: ' ' | ||
} | ||
}; | ||
var payloadAttribute = "payload"; | ||
@@ -30,20 +32,39 @@ if(node.outputlocation && node.outputlocation.length > 0) | ||
} | ||
var output; | ||
switch(node.flow) | ||
{ | ||
case "loginurl": | ||
msg[payloadAttribute] = authClient.code.getUri(); | ||
node.send(msg); | ||
authConfig.auth.authorizeHost = node.auth2Config.authUrl; | ||
authConfig.auth.tokenHost = node.auth2Config.accessTokenUrl; | ||
var client = new AuthorizationCode(authConfig); | ||
var authorizationUri = client.authorizeURL({ | ||
redirect_uri: node.auth2Config.redirectUrl, | ||
scope: node.auth2Config.scope, | ||
state: '' | ||
}); | ||
msg.statusCode = 303; | ||
msg.headers = { | ||
Location: authorizationUri | ||
}; | ||
node.send(msg); | ||
break; | ||
case "gettoken": | ||
authClient.code.getToken(msg.req.originalUrl).then( | ||
function(r){ | ||
msg[payloadAttribute] = r.data; | ||
node.send(msg); | ||
} | ||
).catch( | ||
function(e){ | ||
msg[payloadAttribute] = e.body; | ||
node.send(msg); | ||
}); | ||
break; | ||
authConfig.auth.authorizeHost = node.auth2Config.authUrl; | ||
authConfig.auth.tokenHost = node.auth2Config.accessTokenUrl; | ||
var client = new AuthorizationCode(authConfig); | ||
var tokenParams = { | ||
code: msg.req.query.code, | ||
redirect_uri: node.auth2Config.redirectUrl, | ||
scope: node.auth2Config.scope, | ||
}; | ||
client.getToken(tokenParams).then(function(r) | ||
{ | ||
output = r; | ||
}).catch(function(e){ | ||
output = e.data.payload; | ||
}).finally(function(){ | ||
msg[payloadAttribute] = output; | ||
node.send(msg); | ||
}); | ||
break; | ||
case "usercredential": | ||
@@ -60,9 +81,17 @@ var username = node.auth2Config.username; | ||
} | ||
authClient.owner.getToken(username, password).then(function(r) | ||
authConfig.auth.tokenHost = node.auth2Config.accessTokenUrl; | ||
var client = new ResourceOwnerPassword(authConfig); | ||
var tokenParams = { | ||
username: username, | ||
password: password, | ||
scope: node.auth2Config.scope, | ||
}; | ||
client.getToken(tokenParams).then(function(r) | ||
{ | ||
msg[payloadAttribute] = r.data; | ||
node.send(msg); | ||
output = r; | ||
}).catch(function(e){ | ||
msg[payloadAttribute] = e.body; | ||
node.send(msg); | ||
output = e.data.payload; | ||
}).finally(function(){ | ||
msg[payloadAttribute] = output; | ||
node.send(msg); | ||
}); | ||
@@ -79,3 +108,3 @@ break; | ||
} | ||
RED.nodes.registerType('oauth2 client', oauth2Client); | ||
RED.nodes.registerType('oauth2', oauth2Client); | ||
}; |
@@ -5,4 +5,7 @@ { | ||
"nodes": { | ||
"auth": "lib/auth.js", | ||
"auth-config": "lib/auth-config.js", | ||
"decode":"lib/decode.js", | ||
"jwt": "lib/jwt.js", | ||
"jwt-config": "lib/jwt-config.js", | ||
"basic": "lib/basic.js", | ||
"basic-config": "lib/basic-config.js", | ||
"oauth2-client": "lib/oauth2-client.js", | ||
@@ -12,3 +15,3 @@ "oauth2-client-config": "lib/oauth2-client-config.js" | ||
}, | ||
"version": "1.0.5", | ||
"version": "1.0.7", | ||
"description": "Auth node allows you to integrate security withing your Ignite APIs and apps", | ||
@@ -31,7 +34,6 @@ "scripts": {}, | ||
"dependencies": { | ||
"client-oauth2": "^4.3.3", | ||
"jsonwebtoken": "^8.5.1", | ||
"request": "^2.88.2" | ||
"simple-oauth2": "^4.1.0" | ||
}, | ||
"devDependencies": {} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
2
19
24336
280
1
+ Addedsimple-oauth2@^4.1.0
+ Added@hapi/boom@9.1.4(transitive)
+ Added@hapi/bourne@2.1.0(transitive)
+ Added@hapi/hoek@9.3.0(transitive)
+ Added@hapi/topo@5.1.0(transitive)
+ Added@hapi/wreck@17.2.0(transitive)
+ Added@sideway/address@4.1.5(transitive)
+ Added@sideway/formula@3.0.1(transitive)
+ Added@sideway/pinpoint@2.0.0(transitive)
+ Addeddebug@4.3.5(transitive)
+ Addedjoi@17.13.1(transitive)
+ Addedms@2.1.2(transitive)
+ Addedsimple-oauth2@4.3.0(transitive)
- Removedclient-oauth2@^4.3.3
- Removedrequest@^2.88.2
- Removed@servie/events@1.0.0(transitive)
- Removed@types/tough-cookie@4.0.5(transitive)
- 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.0(transitive)
- Removedbcrypt-pbkdf@1.0.2(transitive)
- Removedbyte-length@1.0.2(transitive)
- Removedcaseless@0.12.0(transitive)
- Removedclient-oauth2@4.3.3(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)
- Removedmake-error@1.3.6(transitive)
- Removedmake-error-cause@2.3.0(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)
- Removedpopsicle@12.1.2(transitive)
- Removedpopsicle-content-encoding@1.0.0(transitive)
- Removedpopsicle-cookie-jar@1.0.1(transitive)
- Removedpopsicle-redirects@1.1.1(transitive)
- Removedpopsicle-transport-http@1.2.1(transitive)
- Removedpopsicle-transport-xhr@2.0.0(transitive)
- Removedpopsicle-user-agent@1.0.0(transitive)
- Removedpsl@1.9.0(transitive)
- Removedpunycode@2.3.1(transitive)
- Removedqs@6.5.3(transitive)
- Removedquerystringify@2.2.0(transitive)
- Removedrequest@2.88.2(transitive)
- Removedrequires-port@1.0.0(transitive)
- Removedsafer-buffer@2.1.2(transitive)
- Removedservie@4.3.3(transitive)
- Removedsshpk@1.18.0(transitive)
- Removedthrowback@4.1.0(transitive)
- Removedtough-cookie@2.5.04.1.4(transitive)
- Removedts-expect@1.3.0(transitive)
- Removedtunnel-agent@0.6.0(transitive)
- Removedtweetnacl@0.14.5(transitive)
- Removeduniversalify@0.2.0(transitive)
- Removeduri-js@4.4.1(transitive)
- Removedurl-parse@1.5.10(transitive)
- Removeduuid@3.4.0(transitive)
- Removedverror@1.10.0(transitive)