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>'
|
||||
, 'URL to app'
|
||||
, String)
|
||||
.option('--identifier <identifier>'
|
||||
, 'identifier'
|
||||
, String)
|
||||
.option('--openid-identifier-url <openidIdentifierUrl>'
|
||||
, 'openidIdentifierUrl'
|
||||
, String
|
||||
, process.env.OPENID_IDENTIFIER_URL)
|
||||
.action(function(options) {
|
||||
if (!options.identifier) {
|
||||
this.missingArgument('--identifier')
|
||||
if (!options.openidIdentifierUrl) {
|
||||
this.missingArgument('--openid-identifier-url')
|
||||
}
|
||||
if (!options.secret) {
|
||||
this.missingArgument('--secret')
|
||||
|
@ -605,7 +606,7 @@ program
|
|||
port: options.port,
|
||||
secret: options.secret,
|
||||
appUrl: options.appUrl,
|
||||
identifier: options.identifier
|
||||
identifierUrl: options.openidIdentifierUrl
|
||||
})
|
||||
})
|
||||
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
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 urljoin = require('url-join')
|
||||
var validator = require('express-validator')
|
||||
var cookieSession = require('cookie-session')
|
||||
var bodyParser = require('body-parser')
|
||||
|
@ -15,16 +19,12 @@ var pathutil = require('../../util/pathutil')
|
|||
var urlutil = require('../../util/urlutil')
|
||||
var lifecycle = require('../../util/lifecycle')
|
||||
|
||||
var openid = require('openid');
|
||||
var url = require('url');
|
||||
var querystring = require('querystring');
|
||||
var extensions = [new openid.SimpleRegistration({
|
||||
"email" : true,
|
||||
"fullname" : true,
|
||||
})];
|
||||
|
||||
|
||||
|
||||
module.exports = function(options) {
|
||||
var verifyUrl = urljoin(options.appUrl, "/auth/verify");
|
||||
|
||||
|
@ -36,9 +36,9 @@ module.exports = function(options) {
|
|||
extensions);
|
||||
|
||||
|
||||
var log = logger.createLogger('auth-mock')
|
||||
, app = express()
|
||||
, server = Promise.promisifyAll(http.createServer(app))
|
||||
var log = logger.createLogger('auth-openid'),
|
||||
app = express(),
|
||||
server = Promise.promisifyAll(http.createServer(app))
|
||||
|
||||
app.set('strict routing', true)
|
||||
app.set('case sensitive routing', true)
|
||||
|
@ -48,20 +48,20 @@ module.exports = function(options) {
|
|||
})
|
||||
|
||||
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){
|
||||
res.send("authentication failed");
|
||||
res.send("auth failed");
|
||||
} else if(!authUrl){
|
||||
res.send("authentication failed");
|
||||
res.send("auth failed");
|
||||
} else {
|
||||
log.info("redirect to authUrl: %s", options.identifier);
|
||||
log.info("redirect to authUrl: %s", options.identifierUrl);
|
||||
res.redirect(authUrl);
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
app.get('/auth/verify', function(req, res){
|
||||
var log = logger.createLogger('auth-openid')
|
||||
log.setLocalIdentifier(req.ip)
|
||||
|
||||
relyingParty.verifyAssertion(req, function(err, result){
|
||||
|
@ -75,10 +75,10 @@ module.exports = function(options) {
|
|||
log.info('Authenticated "%s:%s"', name, email)
|
||||
var token = jwtutil.encode({
|
||||
payload: {
|
||||
email: email
|
||||
, name: name
|
||||
}
|
||||
, secret: options.secret
|
||||
email: email,
|
||||
name: name
|
||||
},
|
||||
secret: options.secret
|
||||
})
|
||||
res.redirect(urlutil.addParams(options.appUrl, {jwt: token}));
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue