Skip to content

Commit 5c7bedd

Browse files
Misc fixes
1 parent 96cacda commit 5c7bedd

File tree

8 files changed

+32
-23
lines changed

8 files changed

+32
-23
lines changed

lib/api/accounts/signin.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ function signin () {
1010
return res.status(400).send('This is not a valid URI')
1111
}
1212

13+
let ldp = req.app.locals.ldp
14+
if (ldp.auth !== 'oidc') {
15+
res
16+
.status(500)
17+
.send('Not implemented')
18+
return
19+
}
20+
1321
request({ method: 'OPTIONS', uri: req.body.webid }, function (err, response) {
1422
if (err) {
1523
res.status(400).send('Did not find a valid endpoint')

lib/capability-discovery.js

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,12 @@ function capabilityDiscovery (corsSettings) {
3131
var router = express.Router('/')
3232

3333
// Advertise the server capability discover endpoint
34-
router.options('*', serviceEndpointHeader, oidcIssuerHeader)
34+
router.options('*', serviceEndpointHeader)
3535
router.get('/.well-known/solid', corsSettings,
3636
serviceCapabilityDocument(serviceConfig))
3737
return router
3838
}
3939

40-
/**
41-
* Advertises the OIDC Issuer endpoint by returning a Link Relation header
42-
* of type `oidc.issuer` on an OPTIONS request.
43-
* Added to avoid an additional request to the serviceCapability document.
44-
* @param req
45-
* @param res
46-
* @param next
47-
*/
48-
function oidcIssuerHeader (req, res, next) {
49-
let oidcIssuerEndpoint = req.app.locals.oidcConfig.issuer
50-
addLink(res, oidcIssuerEndpoint, 'oidc.issuer')
51-
next()
52-
}
53-
5440
/**
5541
* Advertises the server capability endpoint (adds a Link Relation
5642
* header of type `service`, points to the capability document).

lib/create-app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ function createApp (argv = {}) {
9191

9292
// OpenID Connect Auth
9393
if (oidcConfig && ldp.auth === 'oidc') {
94+
app.options('*', oidcHandler.oidcIssuerHeader)
95+
console.log('OIDC is on!')
9496
var oidcRpClient = new OidcRpClient()
9597
// TODO: ensureTrustedClient is async, fix race condition on server startup
9698
debug.idp('Initializing local/trusted client...')

lib/create-server.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ function createServer (argv) {
6060

6161
if (ldp.webid && ldp.auth === 'tls') {
6262
credentials.requestCert = true
63-
// requestCert: true
6463
}
6564

6665
server = https.createServer(credentials, app)

lib/handlers/error-pages.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,20 @@ function handler (err, req, res, next) {
1212
// If the user specifies this function
1313
// then, they can customize the error programmatically
1414
if (ldp.errorHandler) {
15-
return ldp.errorHandler(req, res, next)
15+
return ldp.errorHandler(err, req, res, next)
1616
}
1717

1818
// If noErrorPages is set,
1919
// then use built-in express default error handler
2020
if (ldp.noErrorPages) {
21-
if (err.status === 401 && req.accepts('text/html')) {
21+
if (err.status === 401 &&
22+
req.accepts('text/html') &&
23+
ldp.auth === 'oidc') {
2224
debug('On error pages redirect on 401')
2325
res.status(err.status)
2426
redirectToLogin(req, res, next)
2527
return
2628
}
27-
2829
res
2930
.status(err.status)
3031
.send(err.message + '\n' || '')

lib/handlers/oidc.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ var path = require('path')
1212
module.exports.api = api
1313
module.exports.authenticate = authenticate
1414
module.exports.rpCallback = rpCallback
15+
module.exports.oidcIssuerHeader = oidcIssuerHeader
1516

1617
/**
1718
* OIDC Relying Party API middleware.
@@ -44,6 +45,20 @@ function api (corsSettings) {
4445
return router
4546
}
4647

48+
/**
49+
* Advertises the OIDC Issuer endpoint by returning a Link Relation header
50+
* of type `oidc.issuer` on an OPTIONS request.
51+
* Added to avoid an additional request to the serviceCapability document.
52+
* @param req
53+
* @param res
54+
* @param next
55+
*/
56+
function oidcIssuerHeader (req, res, next) {
57+
let oidcIssuerEndpoint = req.app.locals.oidcConfig.issuer
58+
addLink(res, oidcIssuerEndpoint, 'oidc.issuer')
59+
next()
60+
}
61+
4762
/**
4863
* Authenticates an incoming request. Extracts & verifies access token,
4964
* creates an OIDC client if necessary, etc.

lib/ldp-middleware.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module.exports = LdpMiddleware
33
var express = require('express')
44
var header = require('./header')
55
var acl = require('./acl')
6-
// var authentication = require('./handlers/authentication')
6+
var authentication = require('./handlers/authentication')
77
var get = require('./handlers/get')
88
var post = require('./handlers/post')
99
var put = require('./handlers/put')
@@ -21,7 +21,7 @@ function LdpMiddleware (corsSettings) {
2121
router.use(corsSettings)
2222
}
2323

24-
// router.use('/*', authentication)
24+
router.use('/*', authentication)
2525
router.get('/*', index, acl.allow('Read'), get)
2626
router.post('/*', acl.allow('Append'), post)
2727
router.patch('/*', acl.allow('Append'), patch)

lib/oidc-rp-client.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
'use strict'
2-
var express = require('express')
3-
42
const OIDClientStore = require('./oidc-client-store')
53
const OIDCExpressClient = require('anvil-connect-express')
64
var debug = require('./debug')

0 commit comments

Comments
 (0)