mirror of
https://github.com/openstf/stf
synced 2025-10-04 10:19:30 +02:00
format auth-openid options
This commit is contained in:
parent
4c2da1056d
commit
f942c86aaf
2 changed files with 96 additions and 95 deletions
13
lib/cli.js
13
lib/cli.js
|
@ -587,12 +587,13 @@ program
|
||||||
.option('-a, --app-url <url>'
|
.option('-a, --app-url <url>'
|
||||||
, 'URL to app'
|
, 'URL to app'
|
||||||
, String)
|
, String)
|
||||||
.option('--identifier <identifier>'
|
.option('--openid-identifier-url <openidIdentifierUrl>'
|
||||||
, 'identifier'
|
, 'openidIdentifierUrl'
|
||||||
, String)
|
, String
|
||||||
|
, process.env.OPENID_IDENTIFIER_URL)
|
||||||
.action(function(options) {
|
.action(function(options) {
|
||||||
if (!options.identifier) {
|
if (!options.openidIdentifierUrl) {
|
||||||
this.missingArgument('--identifier')
|
this.missingArgument('--openid-identifier-url')
|
||||||
}
|
}
|
||||||
if (!options.secret) {
|
if (!options.secret) {
|
||||||
this.missingArgument('--secret')
|
this.missingArgument('--secret')
|
||||||
|
@ -605,7 +606,7 @@ program
|
||||||
port: options.port,
|
port: options.port,
|
||||||
secret: options.secret,
|
secret: options.secret,
|
||||||
appUrl: options.appUrl,
|
appUrl: options.appUrl,
|
||||||
identifier: options.identifier
|
identifierUrl: options.openidIdentifierUrl
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
var http = require('http')
|
var http = require('http')
|
||||||
var urljoin = require('url-join')
|
var url = require('url');
|
||||||
|
var querystring = require('querystring');
|
||||||
|
|
||||||
|
var openid = require('openid');
|
||||||
var express = require('express')
|
var express = require('express')
|
||||||
|
var urljoin = require('url-join')
|
||||||
var validator = require('express-validator')
|
var validator = require('express-validator')
|
||||||
var cookieSession = require('cookie-session')
|
var cookieSession = require('cookie-session')
|
||||||
var bodyParser = require('body-parser')
|
var bodyParser = require('body-parser')
|
||||||
|
@ -15,16 +19,12 @@ var pathutil = require('../../util/pathutil')
|
||||||
var urlutil = require('../../util/urlutil')
|
var urlutil = require('../../util/urlutil')
|
||||||
var lifecycle = require('../../util/lifecycle')
|
var lifecycle = require('../../util/lifecycle')
|
||||||
|
|
||||||
var openid = require('openid');
|
|
||||||
var url = require('url');
|
|
||||||
var querystring = require('querystring');
|
|
||||||
var extensions = [new openid.SimpleRegistration({
|
var extensions = [new openid.SimpleRegistration({
|
||||||
"email" : true,
|
"email" : true,
|
||||||
"fullname" : true,
|
"fullname" : true,
|
||||||
})];
|
})];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = function(options) {
|
module.exports = function(options) {
|
||||||
var verifyUrl = urljoin(options.appUrl, "/auth/verify");
|
var verifyUrl = urljoin(options.appUrl, "/auth/verify");
|
||||||
|
|
||||||
|
@ -36,9 +36,9 @@ module.exports = function(options) {
|
||||||
extensions);
|
extensions);
|
||||||
|
|
||||||
|
|
||||||
var log = logger.createLogger('auth-mock')
|
var log = logger.createLogger('auth-openid'),
|
||||||
, app = express()
|
app = express(),
|
||||||
, server = Promise.promisifyAll(http.createServer(app))
|
server = Promise.promisifyAll(http.createServer(app))
|
||||||
|
|
||||||
app.set('strict routing', true)
|
app.set('strict routing', true)
|
||||||
app.set('case sensitive routing', true)
|
app.set('case sensitive routing', true)
|
||||||
|
@ -48,20 +48,20 @@ module.exports = function(options) {
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/auth/openid/', function(req, res) {
|
app.get('/auth/openid/', function(req, res) {
|
||||||
relyingParty.authenticate(options.identifier, false, function(err, authUrl){
|
log.info('openid identifier url: %s', options.identifierUrl)
|
||||||
|
relyingParty.authenticate(options.identifierUrl, false, function(err, authUrl){
|
||||||
if (err){
|
if (err){
|
||||||
res.send("authentication failed");
|
res.send("auth failed");
|
||||||
} else if(!authUrl){
|
} else if(!authUrl){
|
||||||
res.send("authentication failed");
|
res.send("auth failed");
|
||||||
} else {
|
} else {
|
||||||
log.info("redirect to authUrl: %s", options.identifier);
|
log.info("redirect to authUrl: %s", options.identifierUrl);
|
||||||
res.redirect(authUrl);
|
res.redirect(authUrl);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
|
|
||||||
app.get('/auth/verify', function(req, res){
|
app.get('/auth/verify', function(req, res){
|
||||||
var log = logger.createLogger('auth-openid')
|
|
||||||
log.setLocalIdentifier(req.ip)
|
log.setLocalIdentifier(req.ip)
|
||||||
|
|
||||||
relyingParty.verifyAssertion(req, function(err, result){
|
relyingParty.verifyAssertion(req, function(err, result){
|
||||||
|
@ -75,10 +75,10 @@ module.exports = function(options) {
|
||||||
log.info('Authenticated "%s:%s"', name, email)
|
log.info('Authenticated "%s:%s"', name, email)
|
||||||
var token = jwtutil.encode({
|
var token = jwtutil.encode({
|
||||||
payload: {
|
payload: {
|
||||||
email: email
|
email: email,
|
||||||
, name: name
|
name: name
|
||||||
}
|
},
|
||||||
, secret: options.secret
|
secret: options.secret
|
||||||
})
|
})
|
||||||
res.redirect(urlutil.addParams(options.appUrl, {jwt: token}));
|
res.redirect(urlutil.addParams(options.appUrl, {jwt: token}));
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue