wiki-security-social 0.1.0-rc.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.
@@ -0,0 +1,63 @@
1
+ # Federated Wiki - Security Plug-in: Social
2
+
3
+ ## (Configuring "Login to View")
4
+
5
+ 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)
6
+
7
+ 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.
8
+
9
+ 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.
10
+
11
+ **Examples:**
12
+
13
+ If your identity provider is **Google**:
14
+
15
+ ```json
16
+ {
17
+ "admin": { "google": "105396921212328672315" },
18
+ "farm": true,
19
+ "cookieSecret": "0ebf86563b4sdfsdfcc8788e666702",
20
+ "secure_cookie": true,
21
+ "security_type": "passportjs",
22
+ "security_useHttps": true,
23
+ "allowed": "*",
24
+ "wikiDomains": {
25
+ "private.example.com": {
26
+ "admin": { "google": "105396921212328672315" },
27
+ "google_clientID": "10030fghfgh7443-gcemshdl37j67mgpm99eu5dh43li5vrs.apps.googleusercontent.com",
28
+ "google_clientSecret": "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",
29
+ "restricted": true,
30
+ "details": "http://path.ward.asia.wiki.org/login-to-view.html",
31
+ "allowed_domains": ["example1.com", "example2.com"]
32
+ }
33
+ }
34
+ }
35
+ ```
36
+
37
+ If your identity provider is **GitHub**, **Twitter**, or generic **OAuth2**:
38
+
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
+ ```
@@ -0,0 +1,62 @@
1
+ ## Generic OAuth 2
2
+
3
+ ### Login provider set-up
4
+
5
+ Like the other PassportJS login providers, we'll need a separate "OAuth2 Client"
6
+ (others call it an "app", a "product" etc.) for our Federated Wiki instance.
7
+
8
+ How to do this varies slightly for each provider.
9
+
10
+ ### `config.json`
11
+
12
+ In general, you will need to specify:
13
+
14
+ - `oauth2_clientID` -- some systems generate this for you, others allow you to
15
+ specify it
16
+ - `oauth2_clientSecret` -- secure key (keep this secret!)
17
+ - `oauth2_AuthorizationURL` and `oauth2_TokenURL` -- from your login provider's documentation
18
+
19
+ You will also need to specify a callback URL. For some providers, you can add
20
+ this when making a new "OAuth Client" for your wiki, for others you will need to
21
+ specify it with `oauth2_CallbackURL`.
22
+
23
+ You might also need to tell Federated Wiki how to look up usernames:
24
+
25
+ - `oauth2_UserInfoURL` -- from login provider's documentation
26
+ - `oauth2_IdField`, `oauth2_DisplayNameField`, `oauth2_UsernameField` -- starting with
27
+ - `params` for information returned in the original token request, or
28
+ - `profile` for data returned from `oauth2_UserInfoURL`, if you provided it.
29
+
30
+ Sometimes, you'll be able to look up the URLs by visiting your provider's
31
+ `/.well-known/openid-configuration` URL in a web browser.
32
+
33
+ ### Examples
34
+
35
+ #### Nextcloud
36
+
37
+ ```JSON
38
+ {
39
+ "farm": true,
40
+ "admin": {"oauth2": "ID VALUE FROM OWNER.JSON FILE OF ADMIN"},
41
+ "security_type": "social",
42
+ "oauth2_clientID": "CLIENT ID",
43
+ "oauth2_clientSecret": "CLIENT SECRET",
44
+ "oauth2_discoveryUrl": "DISCOVERY URL",
45
+ }
46
+ ```
47
+
48
+ #### Keycloak
49
+
50
+ ```JSON
51
+ {
52
+ "farm": true,
53
+ "admin": {"oauth2": "ID VALUE FROM OWNER.JSON FILE OF ADMIN"},
54
+ "security_type": "passportjs",
55
+ "oauth2_clientID": "CLIENT ID",
56
+ "oauth2_clientSecret": "CLIENT SECRET",
57
+ "oauth2_AuthorizationURL": "https://auth.example.com/auth/realms/Wiki.Cafe/protocol/openid-connect/auth",
58
+ "oauth2_TokenURL": "https://auth.example.com/auth/realms/Wiki.Cafe/protocol/openid-connect/token",
59
+ "oauth2_UserInfoURL": "https://auth.example.com/auth/realms/Wiki.Cafe/protocol/openid-connect/userinfo",
60
+ "oauth2_UsernameField": "profile.preferred_username"
61
+ }
62
+ ```
@@ -0,0 +1,24 @@
1
+ # Federated Wiki - Security Plug-in: Social (Configuration)
2
+
3
+ It is recommended that this plug-in is configured using a configuration file, rather than via the command line.
4
+
5
+ Configuration of this security plug-in is a two stage process:
6
+
7
+ 1. Registering an application with the identity provider, and
8
+ 2. Configuration of the wiki software using information returned in step 1.
9
+
10
+ This plug-in comes with support for using GitHub, Google, and Keycloak(generic OAuth). Although the configuration process is broadly the same for each of these, there are some slight differences.
11
+
12
+ **Although it is possible to configure multiple authentication providers, it is advisable to only configure a single provider. This is to avoid confusing wiki users.**
13
+
14
+ As a wiki server owner you need to pick the you want to use.
15
+
16
+ See, depending on which identity provider you choose to use:
17
+
18
+ - [GitHub](./config-github.md)
19
+ - [Google](./config-google.md)
20
+ - [Keycloak (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
+
24
+ - [Configure Login to View](./config-login-to-view.md)
Binary file
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ console.log('*** loading social')
2
+
3
+ import { default as security } from './server/social.js'
4
+
5
+ export default security
@@ -0,0 +1 @@
1
+ {"inputs":{"node_modules/better-auth/dist/package.mjs":{"bytes":80,"imports":[],"format":"esm"},"node_modules/better-auth/dist/version.mjs":{"bytes":140,"imports":[{"path":"node_modules/better-auth/dist/package.mjs","kind":"import-statement","original":"./package.mjs"}],"format":"esm"},"node_modules/better-auth/dist/client/broadcast-channel.mjs":{"bytes":1388,"imports":[],"format":"esm"},"node_modules/better-auth/dist/client/focus-manager.mjs":{"bytes":1039,"imports":[],"format":"esm"},"node_modules/better-auth/dist/client/online-manager.mjs":{"bytes":1169,"imports":[],"format":"esm"},"node_modules/better-auth/dist/client/parser.mjs":{"bytes":3229,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/task/index.js":{"bytes":582,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/clean-stores/index.js":{"bytes":437,"imports":[{"path":"node_modules/better-auth/node_modules/nanostores/task/index.js","kind":"import-statement","original":"../task/index.js"}],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/atom/index.js":{"bytes":2589,"imports":[{"path":"node_modules/better-auth/node_modules/nanostores/clean-stores/index.js","kind":"import-statement","original":"../clean-stores/index.js"}],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/lifecycle/index.js":{"bytes":4174,"imports":[{"path":"node_modules/better-auth/node_modules/nanostores/clean-stores/index.js","kind":"import-statement","original":"../clean-stores/index.js"}],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/warn/index.js":{"bytes":290,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/computed/index.js":{"bytes":1742,"imports":[{"path":"node_modules/better-auth/node_modules/nanostores/atom/index.js","kind":"import-statement","original":"../atom/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/lifecycle/index.js","kind":"import-statement","original":"../lifecycle/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/warn/index.js","kind":"import-statement","original":"../warn/index.js"}],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/deep-map/path.js":{"bytes":1413,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/deep-map/index.js":{"bytes":795,"imports":[{"path":"node_modules/better-auth/node_modules/nanostores/atom/index.js","kind":"import-statement","original":"../atom/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/warn/index.js","kind":"import-statement","original":"../warn/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/deep-map/path.js","kind":"import-statement","original":"./path.js"},{"path":"node_modules/better-auth/node_modules/nanostores/deep-map/path.js","kind":"import-statement","original":"./path.js"}],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/effect/index.js":{"bytes":448,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/keep-mount/index.js":{"bytes":65,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/listen-keys/index.js":{"bytes":389,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/map/index.js":{"bytes":536,"imports":[{"path":"node_modules/better-auth/node_modules/nanostores/atom/index.js","kind":"import-statement","original":"../atom/index.js"}],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/map-creator/index.js":{"bytes":846,"imports":[{"path":"node_modules/better-auth/node_modules/nanostores/clean-stores/index.js","kind":"import-statement","original":"../clean-stores/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/lifecycle/index.js","kind":"import-statement","original":"../lifecycle/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/map/index.js","kind":"import-statement","original":"../map/index.js"}],"format":"esm"},"node_modules/better-auth/node_modules/nanostores/index.js":{"bytes":697,"imports":[{"path":"node_modules/better-auth/node_modules/nanostores/atom/index.js","kind":"import-statement","original":"./atom/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/clean-stores/index.js","kind":"import-statement","original":"./clean-stores/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/computed/index.js","kind":"import-statement","original":"./computed/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/deep-map/index.js","kind":"import-statement","original":"./deep-map/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/effect/index.js","kind":"import-statement","original":"./effect/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/keep-mount/index.js","kind":"import-statement","original":"./keep-mount/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/lifecycle/index.js","kind":"import-statement","original":"./lifecycle/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/listen-keys/index.js","kind":"import-statement","original":"./listen-keys/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/map-creator/index.js","kind":"import-statement","original":"./map-creator/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/map/index.js","kind":"import-statement","original":"./map/index.js"},{"path":"node_modules/better-auth/node_modules/nanostores/task/index.js","kind":"import-statement","original":"./task/index.js"}],"format":"esm"},"node_modules/better-auth/dist/client/query.mjs":{"bytes":2592,"imports":[{"path":"node_modules/better-auth/node_modules/nanostores/index.js","kind":"import-statement","original":"nanostores"}],"format":"esm"},"node_modules/better-auth/dist/client/session-refresh.mjs":{"bytes":4429,"imports":[{"path":"node_modules/better-auth/dist/client/broadcast-channel.mjs","kind":"import-statement","original":"./broadcast-channel.mjs"},{"path":"node_modules/better-auth/dist/client/focus-manager.mjs","kind":"import-statement","original":"./focus-manager.mjs"},{"path":"node_modules/better-auth/dist/client/online-manager.mjs","kind":"import-statement","original":"./online-manager.mjs"}],"format":"esm"},"node_modules/better-auth/dist/utils/wildcard.mjs":{"bytes":4299,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/@better-auth/core/dist/env/env-impl.mjs":{"bytes":2524,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/@better-auth/core/dist/env/color-depth.mjs":{"bytes":2723,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/env/env-impl.mjs","kind":"import-statement","original":"./env-impl.mjs"}],"format":"esm"},"node_modules/better-auth/node_modules/@better-auth/core/dist/env/logger.mjs":{"bytes":2421,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/env/color-depth.mjs","kind":"import-statement","original":"./color-depth.mjs"}],"format":"esm"},"node_modules/better-auth/node_modules/@better-auth/core/dist/env/index.mjs":{"bytes":431,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/env/env-impl.mjs","kind":"import-statement","original":"./env-impl.mjs"},{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/env/color-depth.mjs","kind":"import-statement","original":"./color-depth.mjs"},{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/env/logger.mjs","kind":"import-statement","original":"./logger.mjs"}],"format":"esm"},"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs":{"bytes":253,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/@better-auth/core/dist/error/codes.mjs":{"bytes":2838,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs","kind":"import-statement","original":"../utils/error-codes.mjs"}],"format":"esm"},"node_modules/better-auth/node_modules/better-call/dist/error.mjs":{"bytes":3722,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/@better-auth/core/dist/error/index.mjs":{"bytes":686,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/error/codes.mjs","kind":"import-statement","original":"./codes.mjs"},{"path":"node_modules/better-auth/node_modules/better-call/dist/error.mjs","kind":"import-statement","original":"better-call/error"}],"format":"esm"},"node_modules/better-auth/dist/utils/url.mjs":{"bytes":10362,"imports":[{"path":"node_modules/better-auth/dist/utils/wildcard.mjs","kind":"import-statement","original":"./wildcard.mjs"},{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/env/index.mjs","kind":"import-statement","original":"@better-auth/core/env"},{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/error/index.mjs","kind":"import-statement","original":"@better-auth/core/error"}],"format":"esm"},"node_modules/better-auth/dist/client/fetch-plugins.mjs":{"bytes":391,"imports":[],"format":"esm"},"node_modules/better-auth/dist/client/session-atom.mjs":{"bytes":863,"imports":[{"path":"node_modules/better-auth/dist/client/query.mjs","kind":"import-statement","original":"./query.mjs"},{"path":"node_modules/better-auth/dist/client/session-refresh.mjs","kind":"import-statement","original":"./session-refresh.mjs"},{"path":"node_modules/better-auth/node_modules/nanostores/index.js","kind":"import-statement","original":"nanostores"}],"format":"esm"},"node_modules/better-auth/node_modules/defu/dist/defu.mjs":{"bytes":2053,"imports":[],"format":"esm"},"node_modules/better-auth/node_modules/@better-fetch/fetch/dist/index.js":{"bytes":22107,"imports":[],"format":"esm"},"node_modules/better-auth/dist/client/config.mjs":{"bytes":3947,"imports":[{"path":"node_modules/better-auth/dist/utils/url.mjs","kind":"import-statement","original":"../utils/url.mjs"},{"path":"node_modules/better-auth/dist/client/parser.mjs","kind":"import-statement","original":"./parser.mjs"},{"path":"node_modules/better-auth/dist/client/fetch-plugins.mjs","kind":"import-statement","original":"./fetch-plugins.mjs"},{"path":"node_modules/better-auth/dist/client/session-atom.mjs","kind":"import-statement","original":"./session-atom.mjs"},{"path":"node_modules/better-auth/node_modules/defu/dist/defu.mjs","kind":"import-statement","original":"defu"},{"path":"node_modules/better-auth/node_modules/@better-fetch/fetch/dist/index.js","kind":"import-statement","original":"@better-fetch/fetch"}],"format":"esm"},"node_modules/better-auth/dist/utils/is-atom.mjs":{"bytes":245,"imports":[],"format":"esm"},"node_modules/better-auth/dist/client/proxy.mjs":{"bytes":2567,"imports":[{"path":"node_modules/better-auth/dist/utils/is-atom.mjs","kind":"import-statement","original":"../utils/is-atom.mjs"}],"format":"esm"},"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/string.mjs":{"bytes":169,"imports":[],"format":"esm"},"node_modules/better-auth/dist/client/vanilla.mjs":{"bytes":703,"imports":[{"path":"node_modules/better-auth/dist/client/config.mjs","kind":"import-statement","original":"./config.mjs"},{"path":"node_modules/better-auth/dist/client/proxy.mjs","kind":"import-statement","original":"./proxy.mjs"},{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/string.mjs","kind":"import-statement","original":"@better-auth/core/utils/string"}],"format":"esm"},"node_modules/better-auth/dist/client/index.mjs":{"bytes":842,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../version.mjs"},{"path":"node_modules/better-auth/dist/client/broadcast-channel.mjs","kind":"import-statement","original":"./broadcast-channel.mjs"},{"path":"node_modules/better-auth/dist/client/focus-manager.mjs","kind":"import-statement","original":"./focus-manager.mjs"},{"path":"node_modules/better-auth/dist/client/online-manager.mjs","kind":"import-statement","original":"./online-manager.mjs"},{"path":"node_modules/better-auth/dist/client/parser.mjs","kind":"import-statement","original":"./parser.mjs"},{"path":"node_modules/better-auth/dist/client/query.mjs","kind":"import-statement","original":"./query.mjs"},{"path":"node_modules/better-auth/dist/client/session-refresh.mjs","kind":"import-statement","original":"./session-refresh.mjs"},{"path":"node_modules/better-auth/dist/client/vanilla.mjs","kind":"import-statement","original":"./vanilla.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/additional-fields/client.mjs":{"bytes":298,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/admin/error-codes.mjs":{"bytes":1700,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs","kind":"import-statement","original":"@better-auth/core/utils/error-codes"}],"format":"esm"},"node_modules/better-auth/dist/plugins/access/access.mjs":{"bytes":1530,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/error/index.mjs","kind":"import-statement","original":"@better-auth/core/error"}],"format":"esm"},"node_modules/better-auth/dist/plugins/admin/access/statement.mjs":{"bytes":815,"imports":[{"path":"node_modules/better-auth/dist/plugins/access/access.mjs","kind":"import-statement","original":"../../access/access.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/admin/has-permission.mjs":{"bytes":554,"imports":[{"path":"node_modules/better-auth/dist/plugins/admin/access/statement.mjs","kind":"import-statement","original":"./access/statement.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/admin/client.mjs":{"bytes":1032,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"},{"path":"node_modules/better-auth/dist/plugins/admin/access/statement.mjs","kind":"import-statement","original":"./access/statement.mjs"},{"path":"node_modules/better-auth/dist/plugins/admin/error-codes.mjs","kind":"import-statement","original":"./error-codes.mjs"},{"path":"node_modules/better-auth/dist/plugins/admin/has-permission.mjs","kind":"import-statement","original":"./has-permission.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/anonymous/error-codes.mjs":{"bytes":771,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs","kind":"import-statement","original":"@better-auth/core/utils/error-codes"}],"format":"esm"},"node_modules/better-auth/dist/plugins/anonymous/client.mjs":{"bytes":553,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"},{"path":"node_modules/better-auth/dist/plugins/anonymous/error-codes.mjs","kind":"import-statement","original":"./error-codes.mjs"}],"format":"esm"},"node_modules/better-auth/dist/client/plugins/infer-plugin.mjs":{"bytes":274,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/custom-session/client.mjs":{"bytes":235,"imports":[{"path":"node_modules/better-auth/dist/client/plugins/infer-plugin.mjs","kind":"import-statement","original":"../../client/plugins/infer-plugin.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/device-authorization/client.mjs":{"bytes":453,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/email-otp/error-codes.mjs":{"bytes":317,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs","kind":"import-statement","original":"@better-auth/core/utils/error-codes"}],"format":"esm"},"node_modules/better-auth/dist/plugins/email-otp/client.mjs":{"bytes":544,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"},{"path":"node_modules/better-auth/dist/plugins/email-otp/error-codes.mjs","kind":"import-statement","original":"./error-codes.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/generic-oauth/error-codes.mjs":{"bytes":827,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs","kind":"import-statement","original":"@better-auth/core/utils/error-codes"}],"format":"esm"},"node_modules/better-auth/dist/plugins/generic-oauth/client.mjs":{"bytes":384,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"},{"path":"node_modules/better-auth/dist/plugins/generic-oauth/error-codes.mjs","kind":"import-statement","original":"./error-codes.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/jwt/client.mjs":{"bytes":497,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/last-login-method/client.mjs":{"bytes":1033,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/magic-link/client.mjs":{"bytes":259,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/multi-session/error-codes.mjs":{"bytes":278,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs","kind":"import-statement","original":"@better-auth/core/utils/error-codes"}],"format":"esm"},"node_modules/better-auth/dist/plugins/multi-session/client.mjs":{"bytes":505,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"},{"path":"node_modules/better-auth/dist/plugins/multi-session/error-codes.mjs","kind":"import-statement","original":"./error-codes.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/oidc-provider/client.mjs":{"bytes":435,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/one-tap/client.mjs":{"bytes":6486,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/one-time-token/client.mjs":{"bytes":273,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/organization/error-codes.mjs":{"bytes":5190,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs","kind":"import-statement","original":"@better-auth/core/utils/error-codes"}],"format":"esm"},"node_modules/better-auth/dist/plugins/organization/access/statement.mjs":{"bytes":1241,"imports":[{"path":"node_modules/better-auth/dist/plugins/access/access.mjs","kind":"import-statement","original":"../../access/access.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/organization/permission.mjs":{"bytes":642,"imports":[],"format":"esm"},"node_modules/better-auth/dist/plugins/organization/client.mjs":{"bytes":3419,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"},{"path":"node_modules/better-auth/dist/client/query.mjs","kind":"import-statement","original":"../../client/query.mjs"},{"path":"node_modules/better-auth/dist/plugins/organization/access/statement.mjs","kind":"import-statement","original":"./access/statement.mjs"},{"path":"node_modules/better-auth/dist/plugins/organization/error-codes.mjs","kind":"import-statement","original":"./error-codes.mjs"},{"path":"node_modules/better-auth/dist/plugins/organization/permission.mjs","kind":"import-statement","original":"./permission.mjs"},{"path":"node_modules/better-auth/node_modules/nanostores/index.js","kind":"import-statement","original":"nanostores"}],"format":"esm"},"node_modules/better-auth/dist/plugins/phone-number/error-codes.mjs":{"bytes":804,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs","kind":"import-statement","original":"@better-auth/core/utils/error-codes"}],"format":"esm"},"node_modules/better-auth/dist/plugins/phone-number/client.mjs":{"bytes":564,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"},{"path":"node_modules/better-auth/dist/plugins/phone-number/error-codes.mjs","kind":"import-statement","original":"./error-codes.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/siwe/client.mjs":{"bytes":314,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/two-factor/error-code.mjs":{"bytes":663,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs","kind":"import-statement","original":"@better-auth/core/utils/error-codes"}],"format":"esm"},"node_modules/better-auth/dist/plugins/two-factor/client.mjs":{"bytes":1236,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"},{"path":"node_modules/better-auth/dist/plugins/two-factor/error-code.mjs","kind":"import-statement","original":"./error-code.mjs"}],"format":"esm"},"node_modules/better-auth/dist/plugins/username/error-codes.mjs":{"bytes":628,"imports":[{"path":"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs","kind":"import-statement","original":"@better-auth/core/utils/error-codes"}],"format":"esm"},"node_modules/better-auth/dist/plugins/username/client.mjs":{"bytes":455,"imports":[{"path":"node_modules/better-auth/dist/version.mjs","kind":"import-statement","original":"../../version.mjs"},{"path":"node_modules/better-auth/dist/plugins/username/error-codes.mjs","kind":"import-statement","original":"./error-codes.mjs"}],"format":"esm"},"node_modules/better-auth/dist/client/plugins/index.mjs":{"bytes":2875,"imports":[{"path":"node_modules/better-auth/dist/plugins/additional-fields/client.mjs","kind":"import-statement","original":"../../plugins/additional-fields/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/admin/error-codes.mjs","kind":"import-statement","original":"../../plugins/admin/error-codes.mjs"},{"path":"node_modules/better-auth/dist/plugins/admin/client.mjs","kind":"import-statement","original":"../../plugins/admin/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/anonymous/error-codes.mjs","kind":"import-statement","original":"../../plugins/anonymous/error-codes.mjs"},{"path":"node_modules/better-auth/dist/plugins/anonymous/client.mjs","kind":"import-statement","original":"../../plugins/anonymous/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/custom-session/client.mjs","kind":"import-statement","original":"../../plugins/custom-session/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/device-authorization/client.mjs","kind":"import-statement","original":"../../plugins/device-authorization/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/email-otp/error-codes.mjs","kind":"import-statement","original":"../../plugins/email-otp/error-codes.mjs"},{"path":"node_modules/better-auth/dist/plugins/email-otp/client.mjs","kind":"import-statement","original":"../../plugins/email-otp/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/generic-oauth/error-codes.mjs","kind":"import-statement","original":"../../plugins/generic-oauth/error-codes.mjs"},{"path":"node_modules/better-auth/dist/plugins/generic-oauth/client.mjs","kind":"import-statement","original":"../../plugins/generic-oauth/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/jwt/client.mjs","kind":"import-statement","original":"../../plugins/jwt/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/last-login-method/client.mjs","kind":"import-statement","original":"../../plugins/last-login-method/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/magic-link/client.mjs","kind":"import-statement","original":"../../plugins/magic-link/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/multi-session/error-codes.mjs","kind":"import-statement","original":"../../plugins/multi-session/error-codes.mjs"},{"path":"node_modules/better-auth/dist/plugins/multi-session/client.mjs","kind":"import-statement","original":"../../plugins/multi-session/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/oidc-provider/client.mjs","kind":"import-statement","original":"../../plugins/oidc-provider/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/one-tap/client.mjs","kind":"import-statement","original":"../../plugins/one-tap/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/one-time-token/client.mjs","kind":"import-statement","original":"../../plugins/one-time-token/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/organization/error-codes.mjs","kind":"import-statement","original":"../../plugins/organization/error-codes.mjs"},{"path":"node_modules/better-auth/dist/plugins/organization/client.mjs","kind":"import-statement","original":"../../plugins/organization/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/phone-number/error-codes.mjs","kind":"import-statement","original":"../../plugins/phone-number/error-codes.mjs"},{"path":"node_modules/better-auth/dist/plugins/phone-number/client.mjs","kind":"import-statement","original":"../../plugins/phone-number/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/siwe/client.mjs","kind":"import-statement","original":"../../plugins/siwe/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/two-factor/error-code.mjs","kind":"import-statement","original":"../../plugins/two-factor/error-code.mjs"},{"path":"node_modules/better-auth/dist/plugins/two-factor/client.mjs","kind":"import-statement","original":"../../plugins/two-factor/client.mjs"},{"path":"node_modules/better-auth/dist/plugins/username/error-codes.mjs","kind":"import-statement","original":"../../plugins/username/error-codes.mjs"},{"path":"node_modules/better-auth/dist/plugins/username/client.mjs","kind":"import-statement","original":"../../plugins/username/client.mjs"},{"path":"node_modules/better-auth/dist/client/plugins/infer-plugin.mjs","kind":"import-statement","original":"./infer-plugin.mjs"}],"format":"esm"},"src/client/auth-dialog.js":{"bytes":1243,"imports":[{"path":"node_modules/better-auth/dist/client/index.mjs","kind":"import-statement","original":"better-auth/client"},{"path":"node_modules/better-auth/dist/client/plugins/index.mjs","kind":"import-statement","original":"better-auth/client/plugins"}],"format":"esm"}},"outputs":{"client/auth-dialog.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":131040},"client/auth-dialog.js":{"imports":[],"exports":[],"entryPoint":"src/client/auth-dialog.js","inputs":{"node_modules/better-auth/dist/package.mjs":{"bytesInOutput":16},"node_modules/better-auth/dist/version.mjs":{"bytesInOutput":10},"node_modules/better-auth/dist/client/broadcast-channel.mjs":{"bytesInOutput":758},"node_modules/better-auth/dist/client/focus-manager.mjs":{"bytesInOutput":553},"node_modules/better-auth/dist/client/online-manager.mjs":{"bytesInOutput":645},"node_modules/better-auth/dist/client/parser.mjs":{"bytesInOutput":2038},"node_modules/better-auth/node_modules/nanostores/atom/index.js":{"bytesInOutput":563},"node_modules/better-auth/node_modules/nanostores/index.js":{"bytesInOutput":0},"node_modules/better-auth/node_modules/nanostores/lifecycle/index.js":{"bytesInOutput":646},"node_modules/better-auth/dist/client/query.mjs":{"bytesInOutput":1186},"node_modules/better-auth/dist/client/session-refresh.mjs":{"bytesInOutput":1976},"node_modules/better-auth/node_modules/@better-auth/core/dist/env/env-impl.mjs":{"bytesInOutput":1009},"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/error-codes.mjs":{"bytesInOutput":112},"node_modules/better-auth/node_modules/better-call/dist/error.mjs":{"bytesInOutput":2029},"node_modules/better-auth/node_modules/@better-auth/core/dist/error/index.mjs":{"bytesInOutput":113},"node_modules/better-auth/dist/utils/url.mjs":{"bytesInOutput":1700},"node_modules/better-auth/dist/client/fetch-plugins.mjs":{"bytesInOutput":191},"node_modules/better-auth/dist/client/session-atom.mjs":{"bytesInOutput":278},"node_modules/better-auth/node_modules/defu/dist/defu.mjs":{"bytesInOutput":823},"node_modules/better-auth/node_modules/@better-fetch/fetch/dist/index.js":{"bytesInOutput":8812},"node_modules/better-auth/dist/client/config.mjs":{"bytesInOutput":2123},"node_modules/better-auth/dist/utils/is-atom.mjs":{"bytesInOutput":121},"node_modules/better-auth/dist/client/proxy.mjs":{"bytesInOutput":1002},"node_modules/better-auth/node_modules/@better-auth/core/dist/utils/string.mjs":{"bytesInOutput":59},"node_modules/better-auth/dist/client/vanilla.mjs":{"bytesInOutput":217},"node_modules/better-auth/dist/plugins/generic-oauth/error-codes.mjs":{"bytesInOutput":586},"node_modules/better-auth/dist/plugins/generic-oauth/client.mjs":{"bytesInOutput":90},"src/client/auth-dialog.js":{"bytesInOutput":518}},"bytes":28298}}}
@@ -0,0 +1 @@
1
+ {"inputs":{"src/server/social.js":{"bytes":10879,"imports":[],"format":"esm"}},"outputs":{"server/social.js.map":{"imports":[],"exports":[],"inputs":{},"bytes":17455},"server/social.js":{"imports":[{"path":"node:url","kind":"import-statement","external":true},{"path":"node:fs","kind":"import-statement","external":true},{"path":"node:path","kind":"import-statement","external":true},{"path":"better-auth","kind":"import-statement","external":true},{"path":"better-auth/plugins","kind":"import-statement","external":true},{"path":"better-auth/node","kind":"import-statement","external":true},{"path":"express-handlebars","kind":"import-statement","external":true}],"exports":["default"],"entryPoint":"src/server/social.js","inputs":{"src/server/social.js":{"bytesInOutput":5502}},"bytes":5610}}}
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "wiki-security-social",
3
+ "version": "0.1.0-rc.0",
4
+ "description": "Social Authentication Security plugin for Federated Wiki.",
5
+ "license": "MIT",
6
+ "author": "Paul Rodwell <paul.rodwell@btinternet.com>",
7
+ "type": "module",
8
+ "main": "index.js",
9
+ "scripts": {
10
+ "build": "npm run test; npm run build:client; npm run build:dialog; npm run build:server",
11
+ "build:client": "npm run clean:client; node scripts/build-client.js",
12
+ "build:dialog": "npm run clean:dialog; node scripts/build-dialog.js",
13
+ "build:server": "npm run clean:server; node scripts/build-server.js",
14
+ "clean": "npm run clean:client; npm run clean:server",
15
+ "clean:client": "rm client/security.js client/security.js.map",
16
+ "clean:dialog": "rm client/auth-dialog.js client/auth-dialog.js.map",
17
+ "clean:server": "rm server/social.js server/social.js.map",
18
+ "test": "node --test"
19
+ },
20
+ "devDependencies": {
21
+ "@eslint/js": "^10.0.1",
22
+ "esbuild": "^0.28.0",
23
+ "eslint": "^10.4.0",
24
+ "grunt-git-authors": "^3.2.0",
25
+ "prettier": "^3.8.3"
26
+ },
27
+ "dependencies": {
28
+ "better-auth": "^1.6.11",
29
+ "express-handlebars": "^9.0.1"
30
+ }
31
+ }
@@ -0,0 +1,5 @@
1
+ /* wiki-security-social - 0.1.0-rc.0 - Sat, 23 May 2026 09:14:43 GMT */
2
+ import m from"node:url";import f from"node:fs";import w from"node:path";import{betterAuth as O}from"better-auth";import{genericOAuth as _}from"better-auth/plugins";import{fromNodeHeaders as y,toNodeHandler as P}from"better-auth/node";import{create as H}from"express-handlebars";console.log("*** security social starting");export default(N,I,t)=>{let k;const i={owner:"",ownerName:"",wikiName:t.url,wikiHost:t.wiki_domain?t.wiki_domain:null,admin:t.admin,statusDir:t.status,idFile:t.id,useHttps:!!t.security_useHttps,callbackProtocol:t.security_useHttps?"https:":m.parse(t.url).protocol,providers:[]};i.callbackHost=i.wikiHost?m.parse(t.url).port?`${i.wikiHost}:${m.parse(t.url).port}`:i.wikiHost:m.parse(t.url).host;const u={};u.retrieveOwner=o=>{f.access(i.idFile,f.constants.F_OK,s=>{s?(i.owner="",o()):f.readFile(i.idFile,(l,d)=>{if(l)return o(l);try{i.owner=JSON.parse(d)}catch(c){console.log(`*** OWNER FILE PROBLEM
3
+ *** Owner File: ${i.idFile}
4
+ *** Error: ${c.message}`),i.owner={name:"unparsable"}}i.ownerName=i.owner.name,o()})})};const p=u.getOwner=()=>i.owner.name||"",b=u.setOwner=(o,s)=>{f.access(i.idFile,f.constants.F_OK,l=>{l?f.writeFile(i.idFile,JSON.stringify(o),d=>{if(d)return s(d);console.log(`Claiming wiki ${i.wikiName} for ${o.name}`),i.owner=o,i.ownerName=o.name,s()}):s("Already Claimed")})};u.getUser=o=>o.user;const S=u.isAuthorized=o=>{if(i.owner==="")return!0;if(o.user){const s=Object.keys(o.user.social);return s.some(l=>i.owner.hasOwnProperty(l))?i.owner[s].id.toString()===o.user.social[s].id.toString():!1}else return!1};return u.isAdmin=o=>{if(typeof i.admin>"u")return!1;try{if(!o.user)return!1}catch{return!1}const s=Object.keys(o.user.social)[0];return i.admin[s]===void 0?(console.log("admin not defined for",s),!1):["github","google","twitter","keycloak"].includes(s)?i.admin[s].toString()===o.user.social[s].id.toString():!1},u.defineRoutes=(o,s,l)=>{const d=H({extname:".html",layoutsDir:w.join(w.dirname(m.fileURLToPath(import.meta.url)),"..","views"),defaultLayout:"securityDialog"}),c={baseURL:`${i.callbackProtocol}//${i.callbackHost}/auth`,basePath:"/auth",socialProviders:{},plugins:[],secret:t.cookieSecret,session:{strategy:"compact",expiresIn:t.session_duration*24*60*60,updateAge:3600*24,cookieCache:{enabled:!0,maxAge:t.session_duration*24*60*60}},cookie:{maxAge:t.session_duration*24*60*60},user:{additionalFields:{social:{type:"object",returned:!0}}},advanced:{crossSubDomainCookies:{enabled:!0},cookiePrefix:"fedwiki",useSecureCookies:!0},trustedOrigins:[`${i.callbackProtocol}//*.${i.callbackHost}`]};["github_clientID","github_clientSecret"].every(e=>e in t)&&(c.socialProviders.github={clientId:t.github_clientID,clientSecret:t.github_clientSecret,mapProfileToUser:async e=>({social:{github:{username:e.login,id:e.id}}})}),["google_clientID","google_clientSecret"].every(e=>e in t)&&(c.socialProviders.google={clientId:t.google_clientID,clientSecret:t.google_clientSecret,mapProfileToUser:async e=>({social:{google:{username:e.name,id:e.sub}}})}),["oauth2_clientID","oauth2_clientSecret","oauth2_discoveryUrl"].every(e=>e in t)&&c.plugins.push(_({config:[{providerId:"oauth2",clientId:t.oauth2_clientID,clientSecret:t.oauth2_clientSecret,discoveryUrl:t.oauth2_discoveryUrl,scopes:["openid","profile","email"],mapProfileToUser:async e=>({social:{oauth2:{id:e.sub,email:e.email,username:e.display_name}}})}]})),k=O(c),o.use(async(e,n,r)=>{const a=await k.api.getSession({headers:y(e.headers)});a?e.user=a.user:e.user="",r()}),o.get("/auth/client-settings.json",(e,n)=>{const r={useHttps:i.useHttps};i.wikiHost&&(r.wikiHost=i.wikiHost),S(e)&&i.owner!=""?r.isOwner=!0:r.isOwner=!1,n.json(r)}),o.get("/auth/loginDialog",(e,n)=>{const r=e.cookies,a=[];c.socialProviders.github&&a.push({button:`<a href='#' onclick='signIn("github")' class='scheme-button github-button'><span>Github</span></a>`}),c.socialProviders.google&&a.push({button:`<a href='#' onclick='signIn("google")' class='scheme-button google-button'><span>Google</span></a>`}),c.plugins.some(h=>h.id==="generic-oauth"&&h.options.config[0].providerId==="oauth2")&&a.push({button:`<a href='#' onclick='signIn("oauth2")' class='scheme-button'><span>OAuth2</span></a>`});const g={wikiName:r.wikiName,wikiHostName:i.wikiHost?"part of "+e.hostname+" wiki farm":"a federated wiki site",title:"Federated Wiki: Site Owner Sign-on",loginText:"Sign in to",schemes:a};d.render(w.join(w.dirname(m.fileURLToPath(import.meta.url)),"..","views","securityDialog.html"),g).then(h=>n.send(h))}),o.get("/auth/loginDone",async(e,n)=>{const r=await k.api.getSession({headers:y(e.headers)}),g={wikiName:e.cookies.wikiName,wikiHostName:i.wikiHost?`part of ${e.hostname} wiki farm`:"a federated wiki site",title:i.owner?"Wiki Site Owner Sign-on":"Sign-on to claim Wiki site",owner:p(),authMessage:"You are now logged in. If this window hasn't closed, you can close it."};d.render(w.join(w.dirname(m.fileURLToPath(import.meta.url)),"..","views","done.html"),g).then(h=>n.send(h))}),o.get("/auth/claim-wiki",(e,n)=>{if(i.owner)console.log("Claim Request Ignored: Wiki already has owner - ",i.wikiName),n.sendStatus(403);else{const r=e.user,a=Object.assign({name:r.name,email:r.email},r.social);b(a,g=>{g&&(console.log("Failed to claim wiki ",e.hostname," for ",a),n.sendStatus(500)),l(p()),n.json({ownerName:a.name})})}}),o.get("/logout",async(e,n)=>{e.session.reset(),n.send("OK")}),o.all("/auth/*splat",async(e,n)=>(e.body&&e.body.provider&&(e.body.providerId=e.body.provider),await P(k)(e,n),{body:e.body}))},u};
5
+ //# sourceMappingURL=social.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/server/social.js"],
4
+ "sourcesContent": ["import url from 'node:url'\nimport fs from 'node:fs'\nimport path from 'node:path'\nimport { betterAuth, socialProviders, keycloak } from 'better-auth'\nimport { genericOAuth } from 'better-auth/plugins'\nimport { fromNodeHeaders, toNodeHandler } from 'better-auth/node'\nimport { create } from 'express-handlebars'\n\n// Private stuff\n\nconsole.log('*** security social starting')\n\nexport default (log, loga, argv) => {\n let auth\n\n const thisWiki = {\n owner: '',\n ownerName: '',\n wikiName: argv.url,\n wikiHost: argv.wiki_domain ? argv.wiki_domain : null,\n admin: argv.admin,\n statusDir: argv.status,\n idFile: argv.id,\n useHttps: argv.security_useHttps ? true : false,\n callbackProtocol: argv.security_useHttps ? 'https:' : url.parse(argv.url).protocol,\n providers: [],\n }\n\n thisWiki.callbackHost = thisWiki.wikiHost\n ? url.parse(argv.url).port\n ? `${thisWiki.wikiHost}:${url.parse(argv.url).port}`\n : thisWiki.wikiHost\n : url.parse(argv.url).host\n\n // Public stuff\n const security = {}\n\n // called by wiki-server\n\n security.retrieveOwner = cb => {\n fs.access(thisWiki.idFile, fs.constants.F_OK, err => {\n if (!err) {\n fs.readFile(thisWiki.idFile, (err, data) => {\n if (err) return cb(err)\n try {\n thisWiki.owner = JSON.parse(data)\n } catch (error) {\n console.log(`*** OWNER FILE PROBLEM\n*** Owner File: ${thisWiki.idFile}\n*** Error: ${error.message}`)\n thisWiki.owner = { name: 'unparsable' }\n }\n thisWiki.ownerName = thisWiki.owner.name\n cb()\n })\n } else {\n thisWiki.owner = ''\n cb()\n }\n })\n }\n\n const getOwner = (security.getOwner = () => {\n const ownerName = thisWiki.owner.name || ''\n return ownerName\n })\n\n const setOwner = (security.setOwner = (id, cb) => {\n fs.access(thisWiki.idFile, fs.constants.F_OK, err => {\n if (err) {\n fs.writeFile(thisWiki.idFile, JSON.stringify(id), err => {\n if (err) return cb(err)\n console.log(`Claiming wiki ${thisWiki.wikiName} for ${id.name}`)\n thisWiki.owner = id\n thisWiki.ownerName = id.name\n cb()\n })\n } else {\n cb('Already Claimed')\n }\n })\n })\n\n security.getUser = req => {\n const user = req.user\n return user\n }\n\n const isAuthorized = (security.isAuthorized = req => {\n if (thisWiki.owner === '') {\n return true\n } else {\n if (req.user) {\n // we have a session - currently there should only be one...\n const idProvider = Object.keys(req.user.social)\n if (idProvider.some(key => thisWiki.owner.hasOwnProperty(key))) {\n if (thisWiki.owner[idProvider].id.toString() === req.user.social[idProvider].id.toString()) {\n return true\n } else {\n return false\n }\n } else {\n return false\n }\n } else {\n return false\n }\n }\n })\n\n security.isAdmin = req => {\n if (typeof thisWiki.admin === 'undefined') {\n return false\n }\n try {\n if (!req.user) {\n return false\n }\n } catch (e) {\n return false\n }\n const idProvider = Object.keys(req.user.social)[0]\n if (thisWiki.admin[idProvider] === undefined) {\n console.log('admin not defined for', idProvider)\n return false\n }\n const adminProviders = ['github', 'google', 'twitter', 'keycloak']\n if (adminProviders.includes(idProvider)) {\n return thisWiki.admin[idProvider].toString() === req.user.social[idProvider].id.toString()\n }\n return false\n }\n\n security.defineRoutes = (app, cors, updateOwner) => {\n // extend views...\n const hbs = create({\n extname: '.html',\n layoutsDir: path.join(path.dirname(url.fileURLToPath(import.meta.url)), '..', 'views'),\n defaultLayout: 'securityDialog',\n })\n\n const authSpec = {\n baseURL: `${thisWiki.callbackProtocol}//${thisWiki.callbackHost}/auth`,\n basePath: '/auth',\n socialProviders: {},\n plugins: [],\n secret: argv.cookieSecret,\n session: {\n strategy: 'compact',\n expiresIn: argv.session_duration * 24 * 60 * 60,\n updateAge: 60 * 60 * 24,\n cookieCache: {\n enabled: true,\n maxAge: argv.session_duration * 24 * 60 * 60,\n },\n },\n cookie: {\n maxAge: argv.session_duration * 24 * 60 * 60,\n },\n user: {\n additionalFields: {\n social: {\n type: 'object',\n returned: true,\n },\n },\n },\n advanced: {\n crossSubDomainCookies: {\n enabled: true,\n },\n cookiePrefix: 'fedwiki',\n useSecureCookies: true,\n },\n trustedOrigins: [`${thisWiki.callbackProtocol}//*.${thisWiki.callbackHost}`],\n }\n\n // Github - uses social sign-on\n if (['github_clientID', 'github_clientSecret'].every(key => key in argv)) {\n authSpec.socialProviders.github = {\n clientId: argv.github_clientID,\n clientSecret: argv.github_clientSecret,\n mapProfileToUser: async profile => {\n return {\n social: {\n github: {\n username: profile.login,\n id: profile.id,\n },\n },\n }\n },\n }\n }\n\n // Google - uses social sign-on\n if (['google_clientID', 'google_clientSecret'].every(key => key in argv)) {\n authSpec.socialProviders.google = {\n clientId: argv.google_clientID,\n clientSecret: argv.google_clientSecret,\n mapProfileToUser: async profile => {\n return {\n social: {\n google: {\n username: profile.name,\n id: profile.sub,\n },\n },\n }\n },\n }\n }\n\n // oauth2 - uses the Generic OAuth plugin, using discovery url\n if (['oauth2_clientID', 'oauth2_clientSecret', 'oauth2_discoveryUrl'].every(key => key in argv)) {\n authSpec.plugins.push(\n genericOAuth({\n config: [\n {\n providerId: 'oauth2',\n clientId: argv.oauth2_clientID,\n clientSecret: argv.oauth2_clientSecret,\n discoveryUrl: argv.oauth2_discoveryUrl,\n scopes: ['openid', 'profile', 'email'],\n mapProfileToUser: async profile => {\n return {\n social: {\n oauth2: {\n id: profile.sub, // This is the UUID from Keycloak\n email: profile.email,\n username: profile.display_name,\n },\n },\n }\n },\n },\n ],\n }),\n )\n }\n\n // add other possible auth providers here.\n\n // configure authenticaiton methods\n auth = betterAuth(authSpec)\n\n app.use(async (req, res, next) => {\n const session = await auth.api.getSession({\n headers: fromNodeHeaders(req.headers),\n })\n if (session) {\n req.user = session.user\n } else {\n req.user = ''\n }\n next()\n })\n\n app.get('/auth/client-settings.json', (req, res) => {\n const settings = {\n useHttps: thisWiki.useHttps,\n }\n if (thisWiki.wikiHost) {\n settings.wikiHost = thisWiki.wikiHost\n }\n if (isAuthorized(req) && thisWiki.owner != '') {\n settings.isOwner = true\n } else {\n settings.isOwner = false\n }\n res.json(settings)\n })\n\n app.get('/auth/loginDialog', (req, res) => {\n const cookies = req.cookies\n const schemeButtons = []\n\n // Github\n if (authSpec.socialProviders.github) {\n schemeButtons.push({\n button: `<a href='#' onclick='signIn(\"github\")' class='scheme-button github-button'><span>Github</span></a>`,\n })\n }\n // Google\n if (authSpec.socialProviders.google) {\n schemeButtons.push({\n button: `<a href='#' onclick='signIn(\"google\")' class='scheme-button google-button'><span>Google</span></a>`,\n })\n }\n\n // OAuth2\n if (authSpec.plugins.some(p => p.id === 'generic-oauth' && p.options.config[0].providerId === 'oauth2')) {\n schemeButtons.push({\n button: `<a href='#' onclick='signIn(\"oauth2\")' class='scheme-button'><span>OAuth2</span></a>`,\n })\n }\n\n const info = {\n wikiName: cookies['wikiName'],\n wikiHostName: thisWiki.wikiHost ? 'part of ' + req.hostname + ' wiki farm' : 'a federated wiki site',\n title: 'Federated Wiki: Site Owner Sign-on',\n loginText: 'Sign in to',\n schemes: schemeButtons,\n }\n\n hbs\n .render(path.join(path.dirname(url.fileURLToPath(import.meta.url)), '..', 'views', 'securityDialog.html'), info)\n .then(rendered => res.send(rendered))\n })\n\n app.get('/auth/loginDone', async (req, res) => {\n const session = await auth.api.getSession({\n headers: fromNodeHeaders(req.headers),\n })\n\n const cookies = req.cookies\n const info = {\n wikiName: cookies['wikiName'],\n wikiHostName: thisWiki.wikiHost ? `part of ${req.hostname} wiki farm` : 'a federated wiki site',\n title: thisWiki.owner ? 'Wiki Site Owner Sign-on' : 'Sign-on to claim Wiki site',\n owner: getOwner(),\n authMessage: \"You are now logged in. If this window hasn't closed, you can close it.\",\n }\n hbs\n .render(path.join(path.dirname(url.fileURLToPath(import.meta.url)), '..', 'views', 'done.html'), info)\n .then(rendered => res.send(rendered))\n })\n\n app.get('/auth/claim-wiki', (req, res) => {\n if (thisWiki.owner) {\n console.log('Claim Request Ignored: Wiki already has owner - ', thisWiki.wikiName)\n res.sendStatus(403)\n } else {\n const user = req.user\n const id = Object.assign(\n {\n name: user.name,\n email: user.email,\n },\n user.social,\n )\n setOwner(id, err => {\n if (err) {\n console.log('Failed to claim wiki ', req.hostname, ' for ', id)\n res.sendStatus(500)\n }\n updateOwner(getOwner())\n res.json({ ownerName: id.name })\n })\n }\n })\n\n app.get('/logout', async (req, res) => {\n req.session.reset()\n res.send('OK')\n })\n\n app.all('/auth/*splat', async (req, res) => {\n // the earlier app.user() will have consumed the body,\n // so we will need to pass it to the handler from the request.\n if (req.body && req.body.provider) {\n req.body.providerId = req.body.provider\n }\n // Pass the body EXPLICITLY to the handler\n return (\n await toNodeHandler(auth)(req, res),\n {\n body: req.body,\n }\n )\n })\n }\n return security\n}\n"],
5
+ "mappings": ";AAAA,OAAOA,MAAS,WAChB,OAAOC,MAAQ,UACf,OAAOC,MAAU,YACjB,OAAS,cAAAC,MAA6C,cACtD,OAAS,gBAAAC,MAAoB,sBAC7B,OAAS,mBAAAC,EAAiB,iBAAAC,MAAqB,mBAC/C,OAAS,UAAAC,MAAc,qBAIvB,QAAQ,IAAI,8BAA8B,EAE1C,cAAe,CAACC,EAAKC,EAAMC,IAAS,CAClC,IAAIC,EAEJ,MAAMC,EAAW,CACf,MAAO,GACP,UAAW,GACX,SAAUF,EAAK,IACf,SAAUA,EAAK,YAAcA,EAAK,YAAc,KAChD,MAAOA,EAAK,MACZ,UAAWA,EAAK,OAChB,OAAQA,EAAK,GACb,SAAU,EAAAA,EAAK,kBACf,iBAAkBA,EAAK,kBAAoB,SAAWV,EAAI,MAAMU,EAAK,GAAG,EAAE,SAC1E,UAAW,CAAC,CACd,EAEAE,EAAS,aAAeA,EAAS,SAC7BZ,EAAI,MAAMU,EAAK,GAAG,EAAE,KAClB,GAAGE,EAAS,QAAQ,IAAIZ,EAAI,MAAMU,EAAK,GAAG,EAAE,IAAI,GAChDE,EAAS,SACXZ,EAAI,MAAMU,EAAK,GAAG,E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S,EAChB,YAAa,wEACf,EACAU,EACG,OAAO1B,EAAK,KAAKA,EAAK,QAAQF,EAAI,cAAc,YAAY,GAAG,CAAC,EAAG,KAAM,QAAS,WAAW,EAAGsC,CAAI,EACpG,KAAKC,GAAYR,EAAI,KAAKQ,CAAQ,CAAC,CACxC,CAAC,EAEDd,EAAI,IAAI,mBAAoB,CAACJ,EAAKU,IAAQ,CACxC,GAAInB,EAAS,MACX,QAAQ,IAAI,mDAAoDA,EAAS,QAAQ,EACjFmB,EAAI,WAAW,GAAG,MACb,CACL,MAAMS,EAAOnB,EAAI,KACXD,EAAK,OAAO,OAChB,CACE,KAAMoB,EAAK,KACX,MAAOA,EAAK,KACd,EACAA,EAAK,MACP,EACArB,EAASC,EAAIL,GAAO,CACdA,IACF,QAAQ,IAAI,wBAAyBM,EAAI,SAAU,QAASD,CAAE,EAC9DW,EAAI,WAAW,GAAG,GAEpBJ,EAAYT,EAAS,CAAC,EACtBa,EAAI,KAAK,CAAE,UAAWX,EAAG,IAAK,CAAC,CACjC,CAAC,CACH,CACF,CAAC,EAEDK,EAAI,IAAI,UAAW,MAAOJ,EAAKU,IAAQ,CACrCV,EAAI,QAAQ,MAAM,EAClBU,EAAI,KAAK,IAAI,CACf,CAAC,EAEDN,EAAI,IAAI,eAAgB,MAAOJ,EAAKU,KAG9BV,EAAI,MAAQA,EAAI,KAAK,WACvBA,EAAI,KAAK,WAAaA,EAAI,KAAK,UAI/B,MAAMf,EAAcK,CAAI,EAAEU,EAAKU,CAAG,EAClC,CACE,KAAMV,EAAI,IACZ,EAEH,CACH,EACOR,CACT",
6
+ "names": ["url", "fs", "path", "betterAuth", "genericOAuth", "fromNodeHeaders", "toNodeHandler", "create", "log", "loga", "argv", "auth", "thisWiki", "security", "cb", "err", "data", "error", "getOwner", "setOwner", "id", "req", "isAuthorized", "idProvider", "key", "app", "cors", "updateOwner", "hbs", "authSpec", "profile", "res", "next", "session", "settings", "cookies", "schemeButtons", "p", "info", "rendered", "user"]
7
+ }
@@ -0,0 +1,72 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,700" rel="stylesheet" type="text/css" />
5
+ <title>{{title}}</title>
6
+ <link id="favicon" href="/favicon.png" rel="icon" type="image/png" />
7
+ <link rel="stylesheet" href="/security/dialog.css" />
8
+ </head>
9
+ <body>
10
+ <div id="content">
11
+ <div class="wikiinfo">
12
+ <div class="table">
13
+ <div class="vertical">
14
+ <img id="wiki_logo" src="//{{wikiName}}/favicon.png" width="32px" height="32px" />
15
+ <h2 id="wiki_name">{{wikiName}}</h2>
16
+ <h3 id="wiki_hostname">{{wikiHostName}}</h3>
17
+ </div>
18
+ </div>
19
+ </div>
20
+ <div id="signIn">
21
+ <div class="table">
22
+ <div class="vertical">
23
+ <div class="contents">
24
+ <div class="scheme_section vcenter" style="width: 249px">
25
+ <div id="message">
26
+ <p>{{authMessage}}</p>
27
+ </div>
28
+ </div>
29
+ </div>
30
+ </div>
31
+ </div>
32
+ </div>
33
+ </div>
34
+ <footer>
35
+ <span id="footerText">
36
+ <strong>Federated Wiki.</strong>
37
+ Sharing ideas through federation.
38
+ <a href="http://fed.wiki/view/welcome-visitors/view/federated-wiki" target="_blank">Learn more→</a>
39
+ </span>
40
+ </footer>
41
+ </body>
42
+ <script type="module">
43
+ // in all probability wikiName was not set, due to the redirect not including the cookie.
44
+ const cookie = await cookieStore.get('wikiName')
45
+ const wikiName = cookie ? cookie.value : window.location.host
46
+ document.querySelector('#wiki_logo').src = `//${wikiName}/favicon.png`
47
+ document.querySelector('#wiki_name').innerText = wikiName
48
+
49
+ document.cookie =
50
+ 'state=loggedIn' + ';domain=.' + window.location.hostname + '; path=/; max-age=60; sameSite=Strict;'
51
+
52
+ const targetOrigin = `${window.location.protocol}//${wikiName}`
53
+ console.log('* target?', targetOrigin)
54
+ if (window.opener) {
55
+ console.log('***we have an opener!', window.opener.location)
56
+ console.log('*', wikiName)
57
+
58
+ window.opener.postMessage(
59
+ {
60
+ type: 'AUTHENTICATION_RESPONSE',
61
+ payload: {
62
+ done: true,
63
+ timestamp: new Date().toString(),
64
+ },
65
+ },
66
+ targetOrigin,
67
+ )
68
+ } else {
69
+ console.log('we have NO opener')
70
+ }
71
+ </script>
72
+ </html>
@@ -0,0 +1,49 @@
1
+ <!doctype html>
2
+ <html>
3
+ <head>
4
+ <link href="https://fonts.googleapis.com/css?family=Open+Sans:400,300,700" rel="stylesheet" type="text/css" />
5
+ <title>{{title}}</title>
6
+ <link id="favicon" href="/favicon.png" rel="icon" type="image/png" />
7
+ <link rel="stylesheet" href="/security/dialog.css" />
8
+ <script type="text/javascript" src="/security/auth-dialog.js"></script>
9
+ "
10
+ </head>
11
+ <body>
12
+ <div id="content">
13
+ <div class="wikiinfo">
14
+ <div class="table">
15
+ <div class="vertical">
16
+ <img id="wiki_logo" src="//{{wikiName}}/favicon.png" width="32px" height="32px" />
17
+ <h2 id="wiki_name">{{wikiName}}</h2>
18
+ <h3 id="wiki_hostname">{{wikiHostName}}</h3>
19
+ </div>
20
+ </div>
21
+ </div>
22
+ <div id="signIn">
23
+ <div class="table">
24
+ <div class="vertical">
25
+ <div class="contents">
26
+ <div class="scheme_section vcenter" style="width: 249px">
27
+ <h2>{{loginText}} {{wikiName}} with...</h2>
28
+ {{#schemes}}
29
+ <p>{{{button}}}</p>
30
+ {{/schemes}} {{#if message}}
31
+ <div id="message">
32
+ <p>{{message}}</p>
33
+ </div>
34
+ {{/if}}
35
+ </div>
36
+ </div>
37
+ </div>
38
+ </div>
39
+ </div>
40
+ </div>
41
+ <footer>
42
+ <span id="footerText">
43
+ <strong>Federated Wiki.</strong>
44
+ Sharing ideas through federation.
45
+ <a href="http://fed.wiki/view/welcome-visitors/view/federated-wiki" target="_blank">Learn more→</a>
46
+ </span>
47
+ </footer>
48
+ </body>
49
+ </html>