wiki-security-passportjs 0.13.0 → 0.14.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -53,7 +53,7 @@ update_footer = function(ownerName, isAuthenticated) {
53
53
  // we update the owner and the login state in the footer, and
54
54
  // populate the security dialog
55
55
  if (ownerName) {
56
- $('footer > #site-owner').html(`Site Owned by: <span id='site-owner' style='text-transform:capitalize;'>${ownerName}</span>`);
56
+ $('footer > #site-owner').html(`Wiki by: <span id='site-owner'>${ownerName}</span>`);
57
57
  }
58
58
  $('footer > #security').empty();
59
59
  if (isAuthenticated) {
@@ -0,0 +1,63 @@
1
+ # Federated Wiki - Security Plug-in: Passport
2
+ ## (Configuring "Login to View")
3
+
4
+ Before attempting to configure Login to View, make sure you have already taken the steps to configure your identity provider as explained [earlier in the documentation](./configuration.md)
5
+
6
+ Where you put your configuration for the Login to View system depends on which sites on your farm you want to be restricted. If you want the whole farm to be restricted then you would add the key-value pairs into the top level of your wiki's `config.json`. If you only want to restrict specific sites on your farm, then you need to restrict them individually within a wikiDomains section of your config.
7
+
8
+ The properties we need to add for Login to View are: `restricted`, `details`, and either `allowed_domains` (Google) or `allowed_ids` (GitHub, Twitter, OAuth2) depending on your identity provider. When using Google auth, `allowed_domains` allows you to specify which domains your user's emails are allowed to be from. Only users with email domains included in this array will be allowed to view the restricted sites. When using GitHub, Twitter, or OAuth2, `allowed_ids` allows you to specify an array of user IDs that are allowed to view the restricted sites. If you set `allowed_ids` equal to `[*]` then any user in your identity provider's system will be allowed to view the restricted sites.
9
+
10
+ **Examples:**
11
+
12
+ If your identity provider is **Google**:
13
+ ```json
14
+ {
15
+ "admin": {"google":"105396921212328672315"},
16
+ "farm": true,
17
+ "cookieSecret": "0ebf86563b4sdfsdfcc8788e666702",
18
+ "secure_cookie": true,
19
+ "security_type": "passportjs",
20
+ "security_useHttps": true,
21
+ "allowed": "*",
22
+ "wikiDomains": {
23
+ "private.example.com": {
24
+ "admin": {"google":"105396921212328672315"},
25
+ "google_clientID": "10030fghfgh7443-gcemshdl37j67mgpm99eu5dh43li5vrs.apps.googleusercontent.com",
26
+ "google_clientSecret": "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",
27
+ "restricted": true,
28
+ "details": "http://path.ward.asia.wiki.org/login-to-view.html",
29
+ "allowed_domains": [
30
+ "example1.com",
31
+ "example2.com"
32
+ ]
33
+ }
34
+ }
35
+ }
36
+ ```
37
+
38
+ If your identity provider is **GitHub**, **Twitter**, or generic **OAuth2**:
39
+ ```json
40
+ {
41
+ "admin": {"oauth2": "admin"},
42
+ "farm": true,
43
+ "cookieSecret": "FDpmzFT2FQZsdfsdfFr4WwZFGuwuVSQ",
44
+ "secure_cookie": true,
45
+ "security_type": "passportjs",
46
+ "security_useHttps": true,
47
+ "allowed": "*",
48
+ "wikiDomains": {
49
+ "wiki.example.com": {
50
+ "oauth2_DisplayNameField": "token.preferred_username",
51
+ "oauth2_IdField": "token.preferred_username",
52
+ "oauth2_clientID": "wiki",
53
+ "oauth2_clientSecret": "3Df5D3jNfsdfsdfsdfNvc08iJOL3uSCg",
54
+ "oauth2_AuthorizationURL": "https://auth.example.com/realms/wiki-cafe-test-server/protocol/openid-connect/auth",
55
+ "oauth2_TokenURL": "https://auth.example.com/realms/wiki-cafe-test-server/protocol/openid-connect/token",
56
+ "oauth2_UsernameField": "token.preferred_username",
57
+ "restricted": true,
58
+ "details": "http://path.ward.asia.wiki.org/login-to-view.html",
59
+ "allowed_ids": ["*"]
60
+ }
61
+ }
62
+ }
63
+ ```
@@ -18,3 +18,6 @@ See, depending on which identity provider you choose to use:
18
18
  * [Google](./config-google.md)
19
19
  * [Twitter](./config-twitter.md)
20
20
  * [Generic OAuth](./config-oauth2.md)
21
+
22
+ With all of the providers above you are also able to configure sites on your farm to be [Login to View](http://ward.asia.wiki.org/login-to-view.html). This means only specified visitors are allowed to view the site's content, rather than it being public on the web. The following page explains how to configure the login-to-view system:
23
+ * [Configure Login to View](./config-login-to-view.md)
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "wiki-security-passportjs",
3
- "version": "0.13.0",
3
+ "version": "0.14.0",
4
4
  "description": "Security plugin for Federated Wiki, using passport.js",
5
5
  "author": "Paul Rodwell <paul.rodwell@btinternet.com> (http://rodwell.me)",
6
6
  "license": "MIT",
7
7
  "dependencies": {
8
8
  "@passport-js/passport-twitter": "^1.0.8",
9
9
  "coffeescript": "^2.4.1",
10
+ "express-handlebars": "^9.0.1",
10
11
  "jwt-decode": "^4.0.0",
11
12
  "lodash": "^4.17.19",
12
13
  "passport": "^0.3.2",
@@ -20,6 +20,8 @@ _ = require 'lodash'
20
20
 
21
21
  passport = require('passport')
22
22
 
23
+ { create } = require('express-handlebars')
24
+
23
25
  # Export a function that generates security handler
24
26
  # when called with options object.
25
27
  module.exports = exports = (log, loga, argv) ->
@@ -64,7 +66,11 @@ module.exports = exports = (log, loga, argv) ->
64
66
  if exists
65
67
  fs.readFile(idFile, (err, data) ->
66
68
  if err then return cb err
67
- owner = JSON.parse(data)
69
+ try
70
+ owner = JSON.parse(data)
71
+ catch error
72
+ console.error "Error parsing owner file #{idFile}", error.message
73
+ owner = { name: 'unparsable' }
68
74
  cb())
69
75
  else
70
76
  owner = ''
@@ -150,6 +156,10 @@ module.exports = exports = (log, loga, argv) ->
150
156
 
151
157
  security.defineRoutes = (app, cors, updateOwner) ->
152
158
 
159
+ hbs = create({
160
+ extname: '.html'
161
+ layoutsDir: path.join(__dirname, '..', 'views')
162
+ defaultLayout: 'securityDialog'})
153
163
  passport.serializeUser = (user, req, done) ->
154
164
  done(null, user)
155
165
 
@@ -366,7 +376,7 @@ module.exports = exports = (log, loga, argv) ->
366
376
  loginText: "Sign in to"
367
377
  schemes: schemeButtons
368
378
  }
369
- res.render(path.join(__dirname, '..', 'views', 'securityDialog.html'), info)
379
+ hbs.render(path.join(__dirname, '..', 'views', 'securityDialog.html'), info).then((rendered) => res.send(rendered))
370
380
 
371
381
  app.get '/auth/loginDone', (req, res) ->
372
382
  cookies = req.cookies
@@ -384,7 +394,7 @@ module.exports = exports = (log, loga, argv) ->
384
394
  owner: getOwner
385
395
  authMessage: "You are now logged in<br>If this window hasn't closed, you can close it."
386
396
  }
387
- res.render(path.join(__dirname, '..', 'views', 'done.html'), info)
397
+ hbs.render(path.join(__dirname, '..', 'views', 'done.html'), info).then((rendered) => res.send(rendered))
388
398
 
389
399
 
390
400
  # if configured, enforce restricted access to json
@@ -475,7 +485,7 @@ module.exports = exports = (log, loga, argv) ->
475
485
  title: "Federated Wiki: Add Alternative Authentication Scheme"
476
486
  schemes: schemeButtons
477
487
  }
478
- res.render(path.join(__dirname, '..', 'views', 'addAlternativeDialog.html'), info)
488
+ hbs.render(path.join(__dirname, '..', 'views', 'addAlternativeDialog.html'), info).then((rendered) => res.send(rendered))
479
489
 
480
490
  else
481
491
  # user is not authenticated