Skip to content

Commit 9b19974

Browse files
Implement Login via WebID-TLS cert local auth strategy
- Disable tls account creation
1 parent 0786e08 commit 9b19974

31 files changed

+1842
-1158
lines changed

config/defaults.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
module.exports = {
44
'auth': 'oidc',
5+
'localAuth': {
6+
'tls': true,
7+
'password': true
8+
},
59
'configPath': './config',
610
'dbPath': './.db',
711
'port': 8443,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
<p>
2+
Registering a new account is disabled for the WebID-TLS authentication method.
3+
Please restart the server using another mode.
4+
</p>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<form method="post" action="/api/accounts/new">
2+
<div class="form-group">
3+
{{#if error}}
4+
<div class="row">
5+
<div class="col-md-12">
6+
<p class="text-danger"><strong>{{error}}</strong></p>
7+
</div>
8+
</div>
9+
{{/if}}
10+
<div class="row">
11+
<div class="col-md-12">
12+
<label for="username">Username:</label>
13+
<input type="text" class="form-control" name="username" id="username" placeholder="alice" />
14+
</div>
15+
</div>
16+
<div class="row">
17+
<div class="col-md-12">
18+
<label for="password">Password:</label>
19+
<input type="password" class="form-control" name="password" id="password" />
20+
</div>
21+
</div>
22+
<div class="row">
23+
<div class="col-md-12">
24+
<label for="name">Name:</label>
25+
<input type="name" class="form-control" name="name" id="name" />
26+
</div>
27+
</div>
28+
<div class="row">
29+
<div class="col-md-12">
30+
<label for="email">Email:</label>
31+
<input type="email" class="form-control" name="email" id="email" />
32+
</div>
33+
</div>
34+
<input type="hidden" name="returnToUrl" value="{{returnToUrl}}" />
35+
</div>
36+
37+
<div class="form-group">
38+
<div class="row">
39+
<div class="col-md-2">
40+
<button type="submit" class="btn btn-primary" id="register">Register</button>
41+
42+
{{> auth/auth-hidden-fields}}
43+
</div>
44+
45+
<div class="col-md-10">
46+
<div>Already have an account?
47+
<a class="btn btn-xs btn-default"
48+
href="{{{loginUrl}}}">
49+
Log In
50+
</a>
51+
</div>
52+
</div>
53+
</div>
54+
</div>
55+
</form>

default-views/account/register.hbs

Lines changed: 5 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,59 +11,11 @@
1111
<h4>Register</h4>
1212
</div>
1313
<div class="container">
14-
<form method="post" action="/api/accounts/new">
15-
<div class="form-group">
16-
{{#if error}}
17-
<div class="row">
18-
<div class="col-md-12">
19-
<p class="text-danger"><strong>{{error}}</strong></p>
20-
</div>
21-
</div>
22-
{{/if}}
23-
<div class="row">
24-
<div class="col-md-12">
25-
<label for="username">Username:</label>
26-
<input type="text" class="form-control" name="username" id="username" placeholder="alice" />
27-
</div>
28-
</div>
29-
<div class="row">
30-
<div class="col-md-12">
31-
<label for="password">Password:</label>
32-
<input type="password" class="form-control" name="password" id="password" />
33-
</div>
34-
</div>
35-
<div class="row">
36-
<div class="col-md-12">
37-
<label for="name">Name:</label>
38-
<input type="name" class="form-control" name="name" id="name" />
39-
</div>
40-
</div>
41-
<div class="row">
42-
<div class="col-md-12">
43-
<label for="email">Email:</label>
44-
<input type="email" class="form-control" name="email" id="email" />
45-
</div>
46-
</div>
47-
<input type="hidden" name="returnToUrl" value="{{returnToUrl}}" />
48-
</div>
49-
50-
<div class="form-group">
51-
<div class="row">
52-
<div class="col-md-2">
53-
<button type="submit" class="btn btn-primary" id="register">Register</button>
54-
</div>
55-
56-
<div class="col-md-10">
57-
<div>Already have an account?
58-
<a class="btn btn-xs btn-default"
59-
href="/login{{#if returnToUrl}}?returnToUrl={{{returnToUrl}}}{{/if}}">
60-
Log In
61-
</a>
62-
</div>
63-
</div>
64-
</div>
65-
</div>
66-
</form>
14+
{{#if registerDisabled}}
15+
{{> account/register-disabled}}
16+
{{else}}
17+
{{> account/register-form}}
18+
{{/if}}
6719
</div>
6820
</body>
6921
</html>
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<input type="hidden" name="response_type" id="response_type" value="{{response_type}}" />
2+
<input type="hidden" name="display" id="display" value="{{display}}" />
3+
<input type="hidden" name="scope" id="scope" value="{{scope}}" />
4+
<input type="hidden" name="client_id" id="client_id" value="{{client_id}}" />
5+
<input type="hidden" name="redirect_uri" id="redirect_uri" value="{{redirect_uri}}" />
6+
<input type="hidden" name="state" id="state" value="{{state}}" />
7+
<input type="hidden" name="nonce" id="nonce" value="{{nonce}}" />

default-views/auth/login-tls.hbs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<form method="post" action="/login/tls">
2+
<div class="form-group">
3+
4+
<button type="submit" class="btn btn-primary" id="login-tls">
5+
With Certificate (WebId-TLS)
6+
</button>
7+
8+
{{> auth/auth-hidden-fields}}
9+
</div>
10+
</form>

default-views/auth/username-password.hbs renamed to default-views/auth/login-username-password.hbs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<form method="post" action="/login">
1+
<form method="post" action="/login/password">
22
<div class="form-group">
33
<div class="row">
44
<div class="col-md-12">
@@ -18,12 +18,6 @@
1818

1919
<button type="submit" class="btn btn-primary" id="login">Log In</button>
2020

21-
<input type="hidden" name="response_type" id="response_type" value="{{response_type}}" />
22-
<input type="hidden" name="display" id="display" value="{{display}}" />
23-
<input type="hidden" name="scope" id="scope" value="{{scope}}" />
24-
<input type="hidden" name="client_id" id="client_id" value="{{client_id}}" />
25-
<input type="hidden" name="redirect_uri" id="redirect_uri" value="{{redirect_uri}}" />
26-
<input type="hidden" name="state" id="state" value="{{state}}" />
27-
<input type="hidden" name="nonce" id="nonce" value="{{nonce}}" />
21+
{{> auth/auth-hidden-fields}}
2822
</div>
2923
</form>

default-views/auth/login.hbs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,15 @@
2020
{{/if}}
2121
<div class="row">
2222
<div class="col-md-5">
23-
{{> auth/username-password}}
23+
{{#if enablePassword}}
24+
{{> auth/login-username-password}}
25+
{{/if}}
2426
</div>
2527
<div class="col-md-1"><br /></div>
2628
<div class="col-md-6">
27-
<a href="/login/tls" class="btn btn-primary">With Certificate (WebId-TLS)</a>
29+
{{#if enableTls}}
30+
{{> auth/login-tls}}
31+
{{/if}}
2832
</div>
2933
</div>
3034
</div>
@@ -34,7 +38,7 @@
3438
<div class="col-md-4">
3539
<div>Don't have an account?
3640
<a class="btn btn-xs btn-default"
37-
href="/register{{#if returnToUrl}}?returnToUrl={{{returnToUrl}}}{{/if}}">
41+
href="{{{registerUrl}}}">
3842
Register
3943
</a>
4044
</div>
@@ -47,7 +51,6 @@
4751
Reset password
4852
</a>
4953
</div>
50-
<div>{{> auth/test}}</div>
5154
</div>
5255
</div>
5356
</div>

lib/api/accounts/user-accounts.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const AddCertificateRequest = require('../../requests/add-cert-request')
1818
function checkAccountExists (accountManager) {
1919
return (req, res, next) => {
2020
let accountUri = req.hostname
21+
2122
accountManager.accountUriExists(accountUri)
2223
.then(found => {
2324
if (!found) {

lib/api/authn/webid-oidc.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
const express = require('express')
77
const bodyParser = require('body-parser').urlencoded({ extended: false })
88

9-
const { LoginByPasswordRequest } = require('../../requests/login-request')
9+
const { LoginRequest } = require('../../requests/login-request')
1010

1111
const PasswordResetEmailRequest = require('../../requests/password-reset-email-request')
1212
const PasswordChangeRequest = require('../../requests/password-change-request')
@@ -33,8 +33,11 @@ function middleware (oidc) {
3333
router.get('/api/auth/select-provider', SelectProviderRequest.get)
3434
router.post('/api/auth/select-provider', bodyParser, SelectProviderRequest.post)
3535

36-
router.get(['/login', '/signin'], LoginByPasswordRequest.get)
37-
router.post(['/login', '/signin'], bodyParser, LoginByPasswordRequest.post)
36+
router.get(['/login', '/signin'], LoginRequest.get)
37+
38+
router.post('/login/password', bodyParser, LoginRequest.loginPassword)
39+
40+
router.post('/login/tls', bodyParser, LoginRequest.loginTls)
3841

3942
router.get('/account/password/reset', PasswordResetEmailRequest.get)
4043
router.post('/account/password/reset', bodyParser, PasswordResetEmailRequest.post)

0 commit comments

Comments
 (0)