Skip to content

Commit e79f025

Browse files
Set User: response header if authenticated (for legacy compat)
1 parent 97dac71 commit e79f025

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

lib/api/authn/index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@ function overrideWith (forceUserId) {
1616
}
1717
}
1818

19+
/**
20+
* Sets the `User:` response header if the user has been authenticated.
21+
*/
22+
function setUserHeader (req, res, next) {
23+
let session = req.session
24+
let webId = session.identified && session.userId
25+
26+
res.set('User', webId || '')
27+
next()
28+
}
29+
1930
module.exports = {
2031
oidc: require('./webid-oidc'),
21-
overrideWith
32+
overrideWith,
33+
setUserHeader
2234
}

lib/api/authn/webid-oidc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,6 @@ function middleware (oidc) {
6464
return router
6565
}
6666

67-
module.exports.middleware = middleware
67+
module.exports = {
68+
middleware
69+
}

lib/create-app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ function initAuthentication (argv, app) {
196196
default:
197197
throw new TypeError('Unsupported authentication scheme')
198198
}
199+
200+
app.use('/', API.authn.setUserHeader)
199201
}
200202

201203
/**

0 commit comments

Comments
 (0)