Skip to content

Commit 75c18da

Browse files
author
Andrei
committed
Merge pull request #346 from solid/auth-config
Making authentication strategy an option
2 parents 2600c8f + 31008df commit 75c18da

6 files changed

Lines changed: 60 additions & 23 deletions

File tree

bin/lib/options.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,28 @@ module.exports = [
2626
name: 'webid',
2727
help: 'Enable WebID+TLS authentication (use `--no-webid` for HTTP instead of HTTPS)',
2828
flag: true,
29-
question: 'Enable WebID-TLS authentication',
29+
question: 'Enable WebID authentication',
3030
prompt: true
3131
},
32+
{
33+
name: 'auth',
34+
help: 'Pick an authentication strategy for WebID: `tls` or `oidc`',
35+
question: 'Select authentication strategy',
36+
type: 'list',
37+
choices: [
38+
'WebID-TLS',
39+
'WebID-OpenID Connect'
40+
],
41+
prompt: true,
42+
default: 'WebID-TLS',
43+
filter: (value) => {
44+
if (value === 'WebID-TLS') return 'tls'
45+
if (value === 'WebID-OpenID Connect') return 'oidc'
46+
},
47+
when: (answers) => {
48+
return answers.webid
49+
}
50+
},
3251
{
3352
name: 'useOwner',
3453
question: 'Do you already have a WebID?',

lib/create-app.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,8 @@ function createApp (argv = {}) {
9595
store: ldp,
9696
suffixAcl: ldp.suffixAcl,
9797
settings: 'settings',
98-
inbox: 'inbox'
98+
inbox: 'inbox',
99+
auth: ldp.auth
99100
})
100101
var needsOverwrite = function (req, res, next) {
101102
checkMasterAcl(req, function (found) {

lib/create-server.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,11 @@ function createServer (argv) {
5555

5656
var credentials = {
5757
key: key,
58-
cert: cert,
59-
requestCert: true
58+
cert: cert
59+
}
60+
61+
if (ldp.webid && ldp.auth === 'tls') {
62+
credentials.requestCert = true
6063
}
6164

6265
server = https.createServer(credentials, app)

lib/handlers/authentication.js

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = handler
22

33
var webid = require('webid/tls')
44
var debug = require('../debug').authentication
5+
var error = require('../http-error')
56

67
function handler (req, res, next) {
78
var ldp = req.app.locals.ldp
@@ -27,27 +28,33 @@ function handler (req, res, next) {
2728
return next()
2829
}
2930

30-
var certificate = req.connection.getPeerCertificate()
31-
// Certificate is empty? skip
32-
if (certificate === null || Object.keys(certificate).length === 0) {
33-
debug('No client certificate found in the request. Did the user click on a cert?')
34-
setEmptySession(req)
35-
return next()
36-
}
37-
38-
// Verify webid
39-
webid.verify(certificate, function (err, result) {
40-
if (err) {
41-
debug('Error processing certificate: ' + err.message)
31+
if (ldp.auth === 'tls') {
32+
var certificate = req.connection.getPeerCertificate()
33+
// Certificate is empty? skip
34+
if (certificate === null || Object.keys(certificate).length === 0) {
35+
debug('No client certificate found in the request. Did the user click on a cert?')
4236
setEmptySession(req)
4337
return next()
4438
}
45-
req.session.userId = result
46-
req.session.identified = true
47-
debug('Identified user: ' + req.session.userId)
48-
res.set('User', req.session.userId)
49-
return next()
50-
})
39+
40+
// Verify webid
41+
webid.verify(certificate, function (err, result) {
42+
if (err) {
43+
debug('Error processing certificate: ' + err.message)
44+
setEmptySession(req)
45+
return next()
46+
}
47+
req.session.userId = result
48+
req.session.identified = true
49+
debug('Identified user: ' + req.session.userId)
50+
res.set('User', req.session.userId)
51+
return next()
52+
})
53+
} else if (ldp.auth === 'oidc') {
54+
return next(error(500, 'OIDC not implemented yet'))
55+
} else {
56+
return next(error(500, 'Authentication method not supported'))
57+
}
5158
}
5259

5360
function setEmptySession (req) {

lib/identity-provider.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ function IdentityProvider (options) {
4141
this.defaultContainers = options.defaultContainers || defaultContainers
4242
this.inbox = options.inbox
4343
this.settings = options.settings
44+
this.auth = options.auth || 'tls'
4445
}
4546

4647
// Generate the future webid from the options and the IdentityProvider Settings
@@ -580,7 +581,9 @@ IdentityProvider.prototype.middleware = function (corsSettings, firstUser) {
580581
}
581582

582583
router.post('/new', parser, setFirstUser(firstUser), this.post.bind(this))
583-
router.post('/cert', parser, this.newCert.bind(this))
584+
if (this.auth === 'tls') {
585+
router.post('/cert', parser, this.newCert.bind(this))
586+
}
584587
router.all('/*', function (req, res) {
585588
var host = uriAbs(req)
586589
// TODO replace the hardcoded link with an arg

lib/ldp.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ function LDP (argv) {
6565
this.skin = true
6666
}
6767

68+
if (this.webid && !this.auth) {
69+
this.auth = 'tls'
70+
}
71+
6872
if (this.proxy && this.proxy[0] !== '/') {
6973
this.proxy = '/' + this.proxy
7074
}

0 commit comments

Comments
 (0)