Skip to content

Commit a5906b8

Browse files
Pre-populate provider on select-provider view
1 parent c6a683d commit a5906b8

File tree

5 files changed

+22
-15
lines changed

5 files changed

+22
-15
lines changed

default-views/auth/select-provider.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
<form method="post" action="/api/auth/select-provider">
1717
<div class="form-group">
1818
<label for="webid">WebID or server URL:</label>
19-
<input type="text" class="form-control" name="webid" id="webid" placeholder="databox.me" />
19+
<input type="text" class="form-control" name="webid" id="webid"
20+
value="{{serverUri}}" />
2021
<input type="hidden" name="returnToUrl" id="returnToUrl" value="" />
2122
</div>
2223
<button type="submit" class="btn btn-primary" id="discover">Submit</button>

lib/api/authn/webid-oidc.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ function middleware (oidc) {
3838

3939
// User-facing Authentication API
4040
router.get('/api/auth/select-provider', (req, res) => {
41-
res.render('auth/select-provider')
41+
let locals = req.app.locals
42+
let serverUri = locals.host.serverUri
43+
res.render('auth/select-provider', { serverUri })
4244
})
4345
router.post('/api/auth/select-provider', bodyParser, selectProvider)
4446

lib/handlers/error-pages.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ function handler (err, req, res, next) {
99

1010
var ldp = req.app.locals.ldp
1111

12+
if (err.status === 401 &&
13+
req.accepts('text/html') &&
14+
ldp.auth === 'oidc') {
15+
debug('401 error - redirect to Select Provider')
16+
res.status(err.status)
17+
redirectToLogin(req, res, next)
18+
return
19+
}
20+
1221
// If the user specifies this function
1322
// then, they can customize the error programmatically
1423
if (ldp.errorHandler) {
@@ -18,14 +27,6 @@ function handler (err, req, res, next) {
1827
// If noErrorPages is set,
1928
// then use built-in express default error handler
2029
if (ldp.noErrorPages) {
21-
if (err.status === 401 &&
22-
req.accepts('text/html') &&
23-
ldp.auth === 'oidc') {
24-
debug('On error pages redirect on 401')
25-
res.status(err.status)
26-
redirectToLogin(req, res, next)
27-
return
28-
}
2930
res
3031
.status(err.status)
3132
.send(err.message + '\n' || '')
@@ -57,7 +58,8 @@ function redirectBody (url) {
5758
<meta http-equiv="refresh" content="0; url=${url}">
5859
</noscript>
5960
<title>Redirecting...</title>
60-
If you are not redirected automatically, follow the <a href='${url}'>link to login</a>
61+
If you are not redirected automatically,
62+
follow the <a href='${url}'>link to login</a>
6163
`
6264
}
6365

@@ -66,9 +68,9 @@ function redirectToLogin (req, res) {
6668
var currentUrl = util.fullUrlForReq(req)
6769
req.session.returnToUrl = currentUrl
6870
let locals = req.app.locals
69-
let loginUrl = locals.host.serverUri + '/api/auth/select-provider?returnToUrl=' +
70-
currentUrl
71-
debug('Redirecting to login: ' + loginUrl)
71+
let loginUrl = locals.host.serverUri +
72+
'/api/auth/select-provider?returnToUrl=' + currentUrl
73+
debug('Redirecting to Select Provider: ' + loginUrl)
7274

7375
var body = redirectBody(loginUrl)
7476
res.send(body)

lib/requests/login-request.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ class LoginByPasswordRequest {
268268
initUserSession (validUser) {
269269
let session = this.session
270270

271+
debug('Initializing user session with webId: ', validUser.webId)
272+
271273
session.userId = validUser.webId
272274
session.identified = true
273275
session.subject = {

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
"node-forge": "^0.6.38",
5959
"nodemailer": "^3.1.4",
6060
"nomnom": "^1.8.1",
61-
"oidc-auth-manager": "^0.2.1",
61+
"oidc-auth-manager": "^0.2.3",
6262
"oidc-op-express": "^0.0.3",
6363
"rdflib": "^0.15.0",
6464
"recursive-readdir": "^2.1.0",

0 commit comments

Comments
 (0)