Skip to content

Commit 188670b

Browse files
committed
Merge branch 'develop' of github.com:solid/node-solid-server into group-acl-integration-uncaught-exception
2 parents f965881 + a6ad3ed commit 188670b

File tree

8 files changed

+4973
-13632
lines changed

8 files changed

+4973
-13632
lines changed

common/popup.html

Lines changed: 3 additions & 4 deletions
Large diffs are not rendered by default.

default-views/auth/login-tls.hbs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<form method="post" action="/login/tls">
1+
<form method="post" action="{{tlsUrl}}">
22
<div class="form-group">
33

44
<button type="submit" class="btn btn-primary" id="login-tls">
@@ -8,33 +8,3 @@
88
{{> auth/auth-hidden-fields}}
99
</div>
1010
</form>
11-
12-
<script type="text/javascript">
13-
const button = document.getElementById('login-tls')
14-
button.addEventListener('click', function(event) {
15-
event.preventDefault()
16-
fetch('/login/tls', { method: 'POST', credentials: 'include' })
17-
.then(function(response) {
18-
const webId = response.headers.get('user')
19-
const idp = new URL(webId).origin
20-
const session = { authType: 'WebID-TLS', webId, idp }
21-
const authClientNamespace = 'solid-auth-client'
22-
let authClientStore
23-
try {
24-
authClientStore = JSON.parse(localStorage.getItem(authClientNamespace) || '{}')
25-
} catch (err) {
26-
authClientStore = {}
27-
}
28-
authClientStore.session = session
29-
localStorage.setItem(authClientNamespace, JSON.stringify(authClientStore))
30-
return response
31-
})
32-
.then(function(response) {
33-
// Temporary solution to restore return URL
34-
// until https://github.com/solid/oidc-auth-manager/issues/17 is resolved
35-
const returnToUrl = localStorage.getItem('returnToUrl')
36-
localStorage.removeItem('returnToUrl')
37-
window.location.href = returnToUrl || '/'
38-
})
39-
})
40-
</script>

default-views/auth/login.hbs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@
3333
</div>
3434
</div>
3535

36+
<script>
37+
// Send return URL from localStorage to server through hidden redirect_uri field
38+
const returnToUrl = localStorage.getItem('returnToUrl')
39+
if (returnToUrl)
40+
for (let redirect of document.getElementsByName("redirect_uri"))
41+
redirect.value = returnToUrl
42+
localStorage.removeItem('returnToUrl')
43+
</script>
44+
3645
<div class="container">
3746
<div class="row">
3847
<div class="col-md-4">

default-views/auth/select-provider.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
</form>
3030
</div>
3131
<script>
32-
// Temporary solution to preserve return URL
33-
// until https://github.com/solid/oidc-auth-manager/issues/17 is resolved
32+
// Preserve return URL in localStorage
33+
// (Do this on the client, because there might be a URL fragment the server can't see)
3434
const locationUrl = new URL(location)
3535
const returnToUrl = locationUrl.searchParams.get('returnToUrl')
3636
localStorage.removeItem('returnToUrl')

lib/requests/login-request.js

Lines changed: 10 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ class LoginRequest extends AuthRequest {
7979
static get (req, res) {
8080
const request = LoginRequest.fromParams(req, res)
8181

82-
request.renderForm()
82+
request.renderForm(null, req)
8383
}
8484

8585
/**
@@ -157,37 +157,19 @@ class LoginRequest extends AuthRequest {
157157
* @return {string}
158158
*/
159159
postLoginUrl (validUser) {
160-
let uri
161-
162-
if (this.authQueryParams['client_id']) {
163-
// Login request is part of an app's auth flow
164-
uri = this.authorizeUrl()
160+
// Login request is part of an app's auth flow
161+
if (/token/.test(this.authQueryParams['response_type'])) {
162+
return this.authorizeUrl()
163+
// Login request is a user going to /login in browser
165164
} else if (validUser) {
166-
// Login request is a user going to /login in browser
167-
// uri = this.accountManager.accountUriFor(validUser.username)
168-
uri = validUser.accountUri
165+
return this.authQueryParams['redirect_uri'] || validUser.accountUri
169166
}
170-
171-
return uri
172167
}
173168

174169
/**
175170
* Redirects the Login request to continue on the OIDC auth workflow.
176171
*/
177172
redirectPostLogin (validUser) {
178-
// TODO: Make the kludge below unnecessary (e.g., by separating OIDC and TLS auth).
179-
// If we have arrived here in the WebID-TLS case,
180-
// this means the client has done an AJAX POST request to /login/tls.
181-
// If the WebID is external, and we send out a redirect to that external URL,
182-
// there is a risk that this external URL returns a non-2xx response.
183-
// This in turn makes the AJAX call on the client fail,
184-
// and its success code is not executed because of that failure.
185-
// To prevent this, we just reply a 204 for external WebIDs.
186-
if (this.authMethod === TLS_AUTH && validUser.externalWebId) {
187-
debug('Login successful with WebID-TLS')
188-
return this.response.header('User', validUser.webId).status(204).send()
189-
}
190-
191173
let uri = this.postLoginUrl(validUser)
192174
debug('Login successful, redirecting to ', uri)
193175
this.response.redirect(uri)
@@ -196,13 +178,15 @@ class LoginRequest extends AuthRequest {
196178
/**
197179
* Renders the login form
198180
*/
199-
renderForm (error) {
181+
renderForm (error, req) {
182+
let queryString = req && req.url && req.url.replace(/[^?]+\?/, '') || ''
200183
let params = Object.assign({}, this.authQueryParams,
201184
{
202185
registerUrl: this.registerUrl(),
203186
returnToUrl: this.returnToUrl,
204187
enablePassword: this.localAuth.password,
205-
enableTls: this.localAuth.tls
188+
enableTls: this.localAuth.tls,
189+
tlsUrl: `/login/tls?${encodeURIComponent(queryString)}`
206190
})
207191

208192
if (error) {

0 commit comments

Comments
 (0)