Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions default-views/auth/login-tls.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@
return response
})
.then(function(response) {
// TODO: redirect to proper location stored in hidden field redirect_uri
// depends on https://github.com/solid/node-solid-server/pull/648
// and https://github.com/solid/oidc-auth-manager/issues/17
window.location.href = '/'
// Temporary solution to restore return URL
// until https://github.com/solid/oidc-auth-manager/issues/17 is resolved
const returnToUrl = localStorage.getItem('returnToUrl')
localStorage.removeItem('returnToUrl')
window.location.href = returnToUrl || '/'
})
})
</script>
15 changes: 11 additions & 4 deletions default-views/auth/select-provider.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,22 @@
{{/if}}
</div>
<div class="container">
<form method="post" action="/api/auth/select-provider">
<form method="post">
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always POST to self, so we don't lose query string.

<div class="form-group">
<label for="webid">WebID or server URL:</label>
<input type="text" class="form-control" name="webid" id="webid"
value="{{serverUri}}" />
<input type="hidden" name="returnToUrl" id="returnToUrl" value="" />
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one was always empty, so rather pointless. Instead, the query string should be used.

<input type="text" class="form-control" name="webid" id="webid" value="{{serverUri}}" />
</div>
<button type="submit" class="btn btn-primary" id="discover">Submit</button>
</form>
</div>
<script>
// Temporary solution to preserve return URL
// until https://github.com/solid/oidc-auth-manager/issues/17 is resolved
const locationUrl = new URL(location)
const returnToUrl = locationUrl.searchParams.get('returnToUrl')
localStorage.removeItem('returnToUrl')
if (returnToUrl && new URL(returnToUrl).host === locationUrl.host)
localStorage.setItem('returnToUrl', returnToUrl)
</script>
</body>
</html>
15 changes: 6 additions & 9 deletions lib/handlers/error-pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,12 @@ function redirectToSelectProvider (req, res) {
res.status(401)
res.header('Content-Type', 'text/html')

let currentUrl = util.fullUrlForReq(req)
req.session.returnToUrl = currentUrl
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can't rely on session, because the server cannot see the hash.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fixed mechanism (not relying on session) will still work on direct requests by the browser (like, requesting an image or a pdf file or whatever), not mediated by a client?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we end up in this code, we are in the process of rendering an HTML error page. So if that's the behavior we exhibit in response to a browser directly requesting an image (I hope not), it's broken for another reason already 😄

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ahh, I see. Makes sense.


let locals = req.app.locals
let loginUrl = locals.host.serverUri +
'/api/auth/select-provider?returnToUrl=' + currentUrl
const locals = req.app.locals
const currentUrl = util.fullUrlForReq(req)
const loginUrl = `${locals.host.serverUri}/api/auth/select-provider?returnToUrl=${encodeURIComponent(currentUrl)}`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Escaping was definitely important here (for query strings and such).

debug('Redirecting to Select Provider: ' + loginUrl)

let body = redirectBody(loginUrl)
const body = redirectBody(loginUrl)
res.send(body)
}

Expand All @@ -188,13 +185,13 @@ function redirectBody (url) {
return `<!DOCTYPE HTML>
<meta charset="UTF-8">
<script>
window.location.href = "${url}" + window.location.hash
window.location.href = "${url}" + encodeURIComponent(window.location.hash)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it is the client who appends the hash (and only the client can do that).

</script>
<noscript>
<meta http-equiv="refresh" content="0; url=${url}">
</noscript>
<title>Redirecting...</title>
If you are not redirected automatically,
If you are not redirected automatically,
follow the <a href='${url}'>link to login</a>
`
}
Expand Down