Skip to content

Commit a0a9a95

Browse files
committed
Allow changing the group separator character
1 parent d81b8f5 commit a0a9a95

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ option](https://oauth2-proxy.github.io/oauth2-proxy/configuration/overview?_high
7676
| Name | Purpose | Default |
7777
| --- | --- | --- |
7878
| `HEADER_USERNAME` | The header to look at for the username. Usernames are matched (ignoring case) with the names of the players in the game. | `x-auth-request-preferred-username` |
79-
| `HEADER_ROLES` | The header to look at for the roles. This must be a comma-separated list. | `x-auth-request-groups` |
79+
| `HEADER_ROLES` | The header to look at for the roles. | `x-auth-request-groups` |
80+
| `HEADER_ROLES_SEPARATOR` | The symbol that is used to separate the roles in the header. | `,` |
8081
| `ROLE_PLAYER` | The role that marks someone as a player. | `role:foundry-vtt:player` |
8182
| `ROLE_ADMIN` | The role that marks someone as an admin. | `role:foundry-vtt:admin` |

patches.sh

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

33
HEADER_USERNAME="${HEADER_USERNAME:-"x-auth-request-preferred-username"}"
44
HEADER_ROLES="${HEADER_ROLES:-"x-auth-request-groups"}"
5+
HEADER_ROLES_SEPARATOR="${HEADER_ROLES_SEPARATOR:-","}"
56
ROLE_PLAYER="${ROLE_PLAYER:-"role:foundry-vtt:player"}"
67
ROLE_ADMIN="${ROLE_ADMIN:-"role:foundry-vtt:admin"}"
78

@@ -45,10 +46,10 @@ patch_append() (
4546
)
4647

4748
# Replace admin password check with header check.
48-
patch_sed admin-header-login resources/app/dist/sessions.mjs "s/testPassword(\(\w\+\)\.body\.adminPassword,\w\+,getSalt(config.passwordSalt))/(s.headers['$HEADER_ROLES'].split(',').includes('$ROLE_ADMIN'))/"
49+
patch_sed admin-header-login resources/app/dist/sessions.mjs "s/testPassword(\(\w\+\)\.body\.adminPassword,\w\+,getSalt(config.passwordSalt))/(s.headers['$HEADER_ROLES'].split('$HEADER_ROLES_SEPARATOR').includes('$ROLE_ADMIN'))/"
4950

5051
# Replace user password check with header check. In addition to the player themselves admins will also be allowed to log in as any player.
51-
patch_sed user-header-login resources/app/dist/sessions.mjs "s/testPassword(\w\+,\(\w\+\)\.password,\w\+.passwordSalt)/((s.headers['$HEADER_USERNAME'].toLowerCase() === \1.name.toLowerCase() \&\& s.headers['$HEADER_ROLES'].split(',').includes('$ROLE_PLAYER')) || s.headers['$HEADER_ROLES'].split(',').includes('$ROLE_ADMIN'))/"
52+
patch_sed user-header-login resources/app/dist/sessions.mjs "s/testPassword(\w\+,\(\w\+\)\.password,\w\+.passwordSalt)/((s.headers['$HEADER_USERNAME'].toLowerCase() === \1.name.toLowerCase() \&\& s.headers['$HEADER_ROLES'].split('$HEADER_ROLES_SEPARATOR').includes('$ROLE_PLAYER')) || s.headers['$HEADER_ROLES'].split('$HEADER_ROLES_SEPARATOR').includes('$ROLE_ADMIN'))/"
5253

5354
# Hide password fields.
5455
patch_append hide-password-fields resources/app/public/css/foundry2.css << END
@@ -59,7 +60,7 @@ patch_append hide-password-fields resources/app/public/css/foundry2.css << END
5960
END
6061

6162
# Pass information about the user info from the headers to the client side. This is used for auto-login behavior, as well as to hide elements that aren't relevant for players.
62-
patch_sed track-header-info resources/app/dist/sessions.mjs "s/global\.logger\.info(\`Created client session \${\(\w\+\)\.id}\`)/(t.headerInfo = { username: s.headers['$HEADER_USERNAME'], isAdmin: s.headers['$HEADER_ROLES']?.split(',')?.includes('$ROLE_ADMIN') ?? false }), &/"
63+
patch_sed track-header-info resources/app/dist/sessions.mjs "s/global\.logger\.info(\`Created client session \${\(\w\+\)\.id}\`)/(t.headerInfo = { username: s.headers['$HEADER_USERNAME'], isAdmin: s.headers['$HEADER_ROLES']?.split('$HEADER_ROLES_SEPARATOR')?.includes('$ROLE_ADMIN') ?? false }), &/"
6364
patch_sed track-header-info resources/app/dist/server/sockets.mjs 's/\(\w\+\)\.sessionId=\(\w\+\)\.id/&,\1.headerInfo = \2.headerInfo/'
6465
patch_sed track-header-info resources/app/public/scripts/foundry.mjs 's/id = response\.sessionId;/& localStorage.headerInfo = JSON.stringify(response.headerInfo);/'
6566
patch_append track-header-info resources/app/public/scripts/foundry.mjs << END

tutorials/authentik_traefik.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ This guide supposes you have a working Authentik and Traefik setup on docker. Sp
66
77
## Modifying the patch
88

9-
You need to modify the patch (`patches.sh`) so that all `split(',')` calles are replaced with `split('|') as Authentik uses `|`as a seprator for multiple roles. This is needed to make the patch work with Authentik. I'm bad at regex and js, so I didn't modify the patch source code to support both`,`and`|`, but you can do it if you want to.
10-
119
You can skip the next 2 sections if you follow this [Tutorial](https://docs.ibracorp.io/authentik/authentik/docker-compose/traefik-forward-auth-single-applications) to set up Authentik with Traefik Forward Auth.
1210

1311
## Traefik Forward Auth Configuration
@@ -70,6 +68,7 @@ foundry:
7068
7169
- HEADER_USERNAME=x-authentik-username # This needs to be lowercase and present as X-authentik-username in traefik dynamic config
7270
- HEADER_ROLES=x-authentik-groups # As above, but X-authentik-groups
71+
- HEADER_ROLES_SEPARATOR='|' # The default is ',', but Authentik uses '|'.
7372
- ROLE_PLAYER=foundry-player # This is the group name you set in Authentik for players
7473
- ROLE_ADMIN=foundry-admin # This is the group name you set in Authentik for admins
7574

0 commit comments

Comments
 (0)