@paramira/authentik-blueprints 0.0.0-stage → 0.2.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 The paramira authors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,91 @@
1
- # Temporary Holding Version
1
+ # @paramira/authentik-blueprints
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ [Authentik](https://goauthentik.io) blueprints for **email-first accounts with
4
+ no passwords**, made for small organisations and communities, for Authentik
5
+ 2026.8.3 (written on 2026.2.3):
6
+
7
+ - **sign-up by email:** the person enters an email, opens the link (on any
8
+ device), picks a username and a display name;
9
+ - **sign-in by email link**, answering the same for addresses that have an
10
+ account and addresses that don't;
11
+ - **no duplicate accounts:** signing up again with a registered address sends
12
+ a sign-in link instead of creating a second account (Authentik itself
13
+ doesn't require unique emails);
14
+ - **invitations with a role:** an invitation's `fixed_data` `{email,
15
+ paramira_role}` fills in the address, refuses another one, and gives the
16
+ role (community, contributor, editor or customer; never admin) once the
17
+ email link is opened; the person then lands on the site's `/welcome`;
18
+ - **a brand** and **link emails in plain words**;
19
+ - **a website as an OpenID Connect client** (confidential, PKCE, strict
20
+ redirect URI, a hashed `sub`, never the email).
21
+
22
+ | File | Holds |
23
+ |---|---|
24
+ | `blueprints/paramira/accounts.yaml` | the site's role groups `paramira-web-community` (everyone, from sign-up), `-contributor`, `-editor`, `-customer`, `-admin` (ADR-0018); sign-up lets the people service see the new account; the flows `paramira-enrollment`, `paramira-login-link` (designated *recovery*: only there does Authentik pretend to send for an unknown address) and `paramira-authentication` (the brand's sign-in, which hands over to the link flow and comes back to the app); the brand |
25
+ | `blueprints/paramira/site.yaml` | the OIDC provider and application `paramira-web`; a `paramira` scope (`user_pk`, `wallet_enrolled`, `wallet_opt_in`, `groups`); the people service (role, account, token `PARAMIRA_PEOPLE_TOKEN`) that moves people between four of the role groups, never admin, and makes, sees and deletes invitations. `apply` gives it its permissions and backfills existing accounts (community, visible to it) |
26
+ | `blueprints/paramira/readfine.yaml` | readfine, the dictionary (paramira-web design 0013, ADR-0053): its own OIDC provider and application `readfine`, with the `paramira` scope from `site.yaml` (the same roles), a strict redirect URI and the grants listed; suspended accounts refused. Environment: `PARAMIRA_READFINE_CLIENT_SECRET` (and `_CLIENT_ID`, `_REDIRECT_URI`, `_URL`) |
27
+ | `templates/paramira/link.html`, `.txt` | the one link email, for sign-up and sign-in |
28
+
29
+ ## Use it
30
+
31
+ Mount the folders into Authentik's server **and** worker, and set the
32
+ environment the blueprints read:
33
+
34
+ ```yaml
35
+ # docker compose, on both server and worker
36
+ volumes:
37
+ - ./node_modules/@paramira/authentik-blueprints/blueprints/paramira:/blueprints/paramira:ro
38
+ - ./node_modules/@paramira/authentik-blueprints/templates:/templates:ro
39
+ environment:
40
+ PARAMIRA_AUTH_DOMAIN: auth.example.org
41
+ PARAMIRA_SITE_CLIENT_ID: paramira-web
42
+ PARAMIRA_SITE_CLIENT_SECRET: ${PARAMIRA_SITE_CLIENT_SECRET} # random, 32+ bytes
43
+ PARAMIRA_SITE_REDIRECT_URI: https://example.org/auth/callback
44
+ PARAMIRA_SITE_URL: https://example.org
45
+ ```
46
+
47
+ The worker applies them on start and whenever a file changes. Email must be
48
+ configured in Authentik (`AUTHENTIK_EMAIL__*`).
49
+
50
+ ## The command
51
+
52
+ ```sh
53
+ npx authentik-blueprints validate # shape, unique ids, !KeyOf only to earlier entries
54
+ npx authentik-blueprints env # the environment variables each blueprint reads
55
+ # with AUTHENTIK_URL and AUTHENTIK_TOKEN (an API token):
56
+ npx authentik-blueprints apply # apply in order, through the API
57
+ npx authentik-blueprints status
58
+ npx authentik-blueprints cleanup [--hours 24] [--dry-run] # remove abandoned sign-ups; run daily
59
+ npx authentik-blueprints invite [--days 7] [--email a@b.org [--role contributor]] # a sign-up link
60
+ ```
61
+
62
+ `invite` without `--email` prints a single-use link for anyone; with it, a
63
+ link bound to that address (another is refused), giving `--role` at sign-up.
64
+
65
+ Sign-up creates the account **inactive**, with a temporary `pending-…`
66
+ username, before sending the link (Authentik's email step needs an existing
67
+ user). `cleanup` removes those still inactive after a day.
68
+
69
+ ## With akantu
70
+
71
+ `setup/authentik.blueprints/` is an [akantu](https://codeberg.org/phuman/akantu)
72
+ tool (tier 1): `check` reports whether every blueprint is applied, `apply`
73
+ applies them, `verify` checks again. Inputs: `url`, and `tokenFile`, a file
74
+ holding the API token (the token itself is never an input).
75
+
76
+ ## Known limits (Authentik 2026.2.3, still so in 2026.8)
77
+
78
+ - Email link tokens are stored in plain text, and a failed send logs the email
79
+ with its link; every `email_sent` event also stores it. Keep links short-lived
80
+ (30 and 10 minutes here) and event retention short.
81
+ - Email codes (6 digits) aren't used: they reveal whether an account exists.
82
+
83
+ ## Tests
84
+
85
+ `pnpm test` runs the static checks; with `AUTHENTIK_URL`, `AUTHENTIK_TOKEN`
86
+ and `MAILPIT_URL` set (paramira-web's `pnpm test:dev`), it also runs the
87
+ flows against a real Authentik: sign-up across two sessions, the
88
+ registered-address case, identical answers, the website's OIDC sign-in to the
89
+ token, and the cleanup.
90
+
91
+ MIT. Part of [paramira-web](https://codeberg.org/phuman/paramira-web).
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env node
2
+ // authentik-blueprints validate | apply | status | env | cleanup [--hours N] [--dry-run]
3
+ // | invite [--name text] [--days N] [--email address [--role R]] | akantu <step>
4
+ // AUTHENTIK_URL and AUTHENTIK_TOKEN (an API token) for apply and status.
5
+ import { readFileSync } from 'node:fs'
6
+ import { createAuthentik } from '@paramira/authentik-client'
7
+ import { applyAll, cleanupPending, envNames, listBlueprints, parseBlueprint, PEOPLE_GROUPS, status, validateAll } from '../src/index.js'
8
+
9
+ const [cmd, ...args] = process.argv.slice(2)
10
+
11
+ process.on('unhandledRejection', (e) => {
12
+ // One line, not an HTML error page.
13
+ console.error(`authentik-blueprints ${cmd}: ${e?.message ?? e}`)
14
+ process.exit(1)
15
+ })
16
+
17
+ function client (url = process.env.AUTHENTIK_URL, token = process.env.AUTHENTIK_TOKEN) {
18
+ if (!url || !token) {
19
+ console.error('set AUTHENTIK_URL and AUTHENTIK_TOKEN')
20
+ process.exit(2)
21
+ }
22
+ return createAuthentik({ baseUrl: url, token })
23
+ }
24
+
25
+ async function akantu (step) {
26
+ // akantu tool contract: one JSON object on stdin, one on stdout.
27
+ const input = JSON.parse(readFileSync(0, 'utf8') || '{}').inputs ?? {}
28
+ const token = input.tokenFile ? readFileSync(input.tokenFile, 'utf8').trim() : ''
29
+ const out = (o) => { process.stdout.write(JSON.stringify(o) + '\n') }
30
+ if (!input.url || !token) return out({ status: step === 'check' ? 'todo' : 'failed', message: 'needs inputs url and tokenFile' })
31
+ const ak = client(input.url, token)
32
+ const notDone = (s) => s.filter((b) => b.status !== 'successful' && b.status !== 'skipped')
33
+ if (step === 'check') {
34
+ const left = notDone(await status(ak))
35
+ return out({ status: left.length ? 'todo' : 'done', message: left.length ? `not applied: ${left.map((b) => b.path).join(', ')}` : 'all applied', outputs: {} })
36
+ }
37
+ if (step === 'apply') {
38
+ const failed = notDone(await applyAll(ak))
39
+ return out({ status: failed.length ? 'failed' : 'ok', message: failed.map((b) => `${b.path}: ${b.status}`).join('; ') || 'applied', outputs: {} })
40
+ }
41
+ const left = notDone(await status(ak))
42
+ return out({ status: left.length ? 'failed' : 'ok', message: left.length ? `not applied: ${left.map((b) => b.path).join(', ')}` : 'all applied', outputs: {} })
43
+ }
44
+
45
+ switch (cmd) {
46
+ case 'validate': {
47
+ const results = validateAll()
48
+ for (const r of results) console.log(r.errors.length ? `✗ ${r.path}\n ${r.errors.join('\n ')}` : `✓ ${r.path}`)
49
+ process.exit(results.some((r) => r.errors.length) ? 1 : 0)
50
+ break
51
+ }
52
+ case 'env':
53
+ for (const { path, file } of listBlueprints()) {
54
+ for (const e of envNames(parseBlueprint(readFileSync(file, 'utf8')))) console.log(`${e.name}${e.hasDefault ? '' : ' (required)'}\t${path}`)
55
+ }
56
+ break
57
+ case 'apply':
58
+ for (const r of await applyAll(client())) console.log(`${r.status === 'successful' ? '✓' : r.status === 'skipped' ? '-' : '✗'} ${r.path}: ${r.status}${r.message ? ` (${r.message})` : ''}`)
59
+ break
60
+ case 'status':
61
+ for (const r of await status(client())) console.log(`${r.path}\t${r.status}\t${r.lastApplied ?? ''}`)
62
+ break
63
+ case 'cleanup': {
64
+ const hours = args.includes('--hours') ? Number(args[args.indexOf('--hours') + 1]) : 24
65
+ if (!Number.isFinite(hours) || hours < 1) { console.error('--hours must be at least 1'); process.exit(2) }
66
+ const dryRun = args.includes('--dry-run')
67
+ const names = await cleanupPending(client(), { olderThanHours: hours, dryRun })
68
+ console.log(`${dryRun ? 'would remove' : 'removed'} ${names.length} abandoned sign-up(s)${names.length ? ': ' + names.join(', ') : ''}`)
69
+ break
70
+ }
71
+ case 'invite': {
72
+ // A sign-up link (sign-up is invite-only unless PARAMIRA_SIGNUP_OPEN=true).
73
+ // With --email, bound to that address (another is refused) and, with
74
+ // --role, giving that role at sign-up (never admin; ADR-0030), the same
75
+ // rules as /admin/invites. Without, a single-use link for anyone.
76
+ const opt = (flag) => (args.includes(flag) ? args[args.indexOf(flag) + 1] : undefined)
77
+ const days = opt('--days') ? Number(opt('--days')) : 7
78
+ if (!Number.isFinite(days) || days <= 0 || days > 90) { console.error('--days must be between 1 and 90'); process.exit(2) }
79
+ const email = opt('--email')?.trim().toLowerCase()
80
+ const role = opt('--role')
81
+ const ROLES = PEOPLE_GROUPS.map((g) => g.replace('paramira-web-', ''))
82
+ if (role && !email) { console.error('--role needs --email: a role is only given to the address invited'); process.exit(2) }
83
+ if (role && !ROLES.includes(role)) { console.error(`--role is one of ${ROLES.join(', ')} (admin is given in Authentik only)`); process.exit(2) }
84
+ if (email && !/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { console.error('--email: not an email address'); process.exit(2) }
85
+ const name = opt('--name') ?? `invite-${new Date().toISOString().slice(0, 10)}`
86
+ const ak = client()
87
+ const invitation = await ak.invitations.create({
88
+ name: name.toLowerCase().replace(/[^a-z0-9-]+/g, '-').slice(0, 50),
89
+ flowSlug: 'paramira-enrollment',
90
+ // Bound to an address, more uses give nothing more; a single-use link
91
+ // is spent when first opened.
92
+ singleUse: !email,
93
+ expires: new Date(Date.now() + days * 86400_000),
94
+ ...(email && { fixedData: { email, ...(role && { paramira_role: role }) } })
95
+ })
96
+ console.log(ak.invitations.link(invitation, 'paramira-enrollment'))
97
+ console.error(email ? `for ${email}${role ? ` as ${role}` : ''}, valid for ${days} day(s)` : `single use, valid for ${days} day(s)`)
98
+ break
99
+ }
100
+ case 'akantu':
101
+ await akantu(args[0])
102
+ break
103
+ default:
104
+ console.error('usage: authentik-blueprints validate | env | apply | status | cleanup [--hours N] [--dry-run] | invite [--name text] [--days N] [--email address [--role R]] | akantu <check|apply|verify>')
105
+ process.exit(2)
106
+ }
@@ -0,0 +1,438 @@
1
+ # paramira org accounts: email-first sign-up, email-link sign-in, the brand.
2
+ # Design 0001 (paramira-web), ADR-0003/0004. Authentik 2026.2.3.
3
+ #
4
+ # paramira-enrollment Prompt email -> [new address: User Write, inactive,
5
+ # temporary username | registered address: that
6
+ # account becomes the pending user] -> Email stage
7
+ # (link, 30 min, activates) -> [new only: Prompt
8
+ # profile -> User Write] -> User Login
9
+ # paramira-login-link (designated recovery, so unknown addresses look
10
+ # the same) Identification -> Email stage (link,
11
+ # 10 min) -> User Login
12
+ # paramira-authentication the brand's sign-in: redirects to the link flow,
13
+ # keeping the context (the app it came from)
14
+ #
15
+ # Entries refer only to earlier ones (!KeyOf), so flows come before stages.
16
+ #
17
+ # Environment (on Authentik's server and worker):
18
+ # PARAMIRA_AUTH_DOMAIN the brand's domain: a domain of its own when the
19
+ # Authentik is shared (e.g. login.paramira.org), so
20
+ # other apps keep their brand and flows
21
+ # PARAMIRA_SITE_URL where someone who signed up from an invitation
22
+ # lands (its /welcome)
23
+ # PARAMIRA_SIGNUP_OPEN "true" lets anyone sign up; otherwise (default)
24
+ # sign-up needs an invitation link
25
+ # (authentik-blueprints invite, or /admin/invites)
26
+ #
27
+ # An invitation may carry `fixed_data` {email, paramira_role} (ADR-0030):
28
+ # the email prompt is filled with the email, another address is refused,
29
+ # and once the link in the email was opened the account gets the role if it
30
+ # is community, contributor, editor or customer (never admin).
31
+ #
32
+ # A suspended account (in paramira-web-suspended, never an admin: ADR-0036)
33
+ # is refused once its email link is opened, in both flows.
34
+ version: 1
35
+ metadata:
36
+ name: paramira-accounts
37
+ labels:
38
+ blueprints.goauthentik.io/description: "paramira: org accounts (sign-up and sign-in by email)"
39
+ entries:
40
+ # Groups: the site's roles (design 0003, ADR-0018). Everyone joins
41
+ # community at sign-up; an admin moves people between community,
42
+ # contributor, editor and customer (the people service, site.yaml); admin
43
+ # is given only here, in Authentik. A person can be in several.
44
+ - model: authentik_core.group
45
+ id: g-members
46
+ identifiers: {name: paramira-web-community}
47
+ - model: authentik_core.group
48
+ id: g-contributors
49
+ identifiers: {name: paramira-web-contributor}
50
+ - model: authentik_core.group
51
+ id: g-editors
52
+ identifiers: {name: paramira-web-editor}
53
+ - model: authentik_core.group
54
+ id: g-customers
55
+ identifiers: {name: paramira-web-customer}
56
+ - model: authentik_core.group
57
+ id: g-admins
58
+ identifiers: {name: paramira-web-admin}
59
+ # Suspended accounts (ADR-0036): refused by the flows below and by the
60
+ # site's and chat's applications; an admin never is.
61
+ - model: authentik_core.group
62
+ id: g-suspended
63
+ identifiers: {name: paramira-web-suspended}
64
+
65
+ # Prompts
66
+ - model: authentik_stages_prompt.prompt
67
+ id: p-email
68
+ identifiers: {name: paramira-email}
69
+ attrs: {field_key: email, label: Email, type: email, required: true, placeholder: you@example.org, order: 0}
70
+ - model: authentik_stages_prompt.prompt
71
+ id: p-username
72
+ identifiers: {name: paramira-username}
73
+ attrs:
74
+ field_key: username
75
+ label: Username
76
+ type: username
77
+ required: true
78
+ order: 0
79
+ sub_text: Shown to other people. Letters, numbers, dots and dashes.
80
+ - model: authentik_stages_prompt.prompt
81
+ id: p-name
82
+ identifiers: {name: paramira-name}
83
+ attrs: {field_key: name, label: Display name, type: text, required: true, order: 1}
84
+ - model: authentik_stages_prompt.prompt
85
+ id: p-wallet
86
+ identifiers: {name: paramira-wallet-opt-in}
87
+ attrs:
88
+ field_key: attributes.paramira.wallet_opt_in
89
+ label: I want to sign in with an identity wallet too
90
+ type: checkbox
91
+ required: false
92
+ order: 2
93
+ sub_text: Optional. You can always sign in by email.
94
+
95
+ # Policies
96
+ - model: authentik_policies_expression.expressionpolicy
97
+ id: pol-new-or-existing
98
+ identifiers: {name: paramira-enrollment-new-or-existing}
99
+ attrs:
100
+ expression: |
101
+ # Bound to the "create the account" step of sign-up. A registered,
102
+ # active address doesn't get a second account: that account becomes
103
+ # the pending user, the step is skipped, and the email sent next is a
104
+ # sign-in link. A new address gets a temporary username.
105
+ import secrets
106
+ plan = request.context["flow_plan"]
107
+ data = plan.context.setdefault("prompt_data", {})
108
+ email = (data.get("email") or "").strip().lower()
109
+ if not email:
110
+ return False
111
+ data["email"] = email
112
+ existing = ak_user_by(email__iexact=email, is_active=True)
113
+ if existing:
114
+ plan.context["pending_user"] = existing
115
+ plan.context["paramira_existing_account"] = True
116
+ return False
117
+ plan.context["paramira_existing_account"] = False
118
+ data["username"] = "pending-" + secrets.token_hex(8)
119
+ return True
120
+ - model: authentik_policies_expression.expressionpolicy
121
+ id: pol-forget-temp-username
122
+ identifiers: {name: paramira-enrollment-forget-temporary-username}
123
+ attrs:
124
+ expression: |
125
+ # Bound to the email-link step, after the account was created: the
126
+ # temporary username must not come back pre-filled in the profile step.
127
+ data = request.context["flow_plan"].context.get("prompt_data", {})
128
+ if str(data.get("username", "")).startswith("pending-"):
129
+ del data["username"]
130
+ return True
131
+ - model: authentik_policies_expression.expressionpolicy
132
+ id: pol-people-can-see
133
+ identifiers: {name: paramira-enrollment-people-can-see}
134
+ attrs:
135
+ expression: |
136
+ # Bound to the email-link step, after the account was created: the
137
+ # people service (site.yaml) may see this account, so an admin can
138
+ # give it a role. It sees paramira accounts only, never the other
139
+ # apps' users on a shared Authentik (design 0003, ADR-0018).
140
+ from authentik.rbac.models import Role
141
+ # An account just made for a new address (still pending) may also be
142
+ # deleted by it, so an abandoned sign-up can be cleared from the
143
+ # site; taken back when sign-up finishes (pol-people-cannot-delete).
144
+ plan = request.context["flow_plan"]
145
+ user = plan.context.get("pending_user")
146
+ role = Role.objects.filter(name="paramira-people").first()
147
+ if user is not None and user.pk and role is not None:
148
+ role.assign_perms("authentik_core.view_user", obj=user)
149
+ if not plan.context.get("paramira_existing_account") and not user.is_active and user.username.startswith("pending-"):
150
+ role.assign_perms("authentik_core.delete_user", obj=user)
151
+ return True
152
+ - model: authentik_policies_expression.expressionpolicy
153
+ id: pol-people-cannot-delete
154
+ identifiers: {name: paramira-enrollment-people-cannot-delete}
155
+ attrs:
156
+ expression: |
157
+ # Bound to the last step (signing in): the account is no longer an
158
+ # abandoned sign-up, so the people service may no longer delete it.
159
+ from authentik.rbac.models import Role
160
+ user = request.context["flow_plan"].context.get("pending_user")
161
+ role = Role.objects.filter(name="paramira-people").first()
162
+ if user is not None and user.pk and role is not None:
163
+ role.remove_perms("authentik_core.delete_user", obj=user)
164
+ return True
165
+ - model: authentik_policies_expression.expressionpolicy
166
+ id: pol-suspended
167
+ identifiers: {name: paramira-suspended}
168
+ attrs:
169
+ expression: |
170
+ # Passes for a suspended account (ADR-0036), never an admin: in a
171
+ # flow, the account signing in; on an application (bound negated),
172
+ # the person asking for it.
173
+ plan = request.context.get("flow_plan")
174
+ user = plan.context.get("pending_user") if plan else request.user
175
+ if user is None or not user.pk:
176
+ return False
177
+ return ak_is_group_member(user, name="paramira-web-suspended") and not ak_is_group_member(user, name="paramira-web-admin")
178
+ - model: authentik_policies_expression.expressionpolicy
179
+ id: pol-own-username
180
+ identifiers: {name: paramira-enrollment-own-username}
181
+ attrs:
182
+ expression: |
183
+ # Validation of the profile step: a username of the person's own.
184
+ username = str(request.context.get("prompt_data", {}).get("username", "")).strip()
185
+ if not username or username.lower().startswith("pending-"):
186
+ ak_message("Choose a username of your own.")
187
+ return False
188
+ return True
189
+ - model: authentik_policies_expression.expressionpolicy
190
+ id: pol-new-only
191
+ identifiers: {name: paramira-enrollment-new-account-only}
192
+ attrs:
193
+ expression: |
194
+ # The profile steps run only for a new account. (Whether this is the
195
+ # first sign-in is tracked by the site itself.)
196
+ plan = request.context["flow_plan"]
197
+ return not plan.context.get("paramira_existing_account", False)
198
+ - model: authentik_policies_expression.expressionpolicy
199
+ id: pol-not-invited-email
200
+ identifiers: {name: paramira-enrollment-not-the-invited-email}
201
+ attrs:
202
+ expression: |
203
+ # Bound to the step that refuses sign-up: passes (so the sign-up is
204
+ # refused) when an invitation names an email and this isn't it. A
205
+ # forwarded invitation gives nothing (ADR-0030).
206
+ plan = request.context["flow_plan"]
207
+ invite = plan.context.get("invitation")
208
+ invited = str((invite.fixed_data or {}).get("email", "") if invite else "").strip().lower()
209
+ given = str(plan.context.get("prompt_data", {}).get("email", "")).strip().lower()
210
+ return bool(invited) and given != invited
211
+ - model: authentik_policies_expression.expressionpolicy
212
+ id: pol-invited-role
213
+ identifiers: {name: paramira-enrollment-invited-role}
214
+ attrs:
215
+ expression: |
216
+ # Bound to the last step (signing in), after the email link was
217
+ # opened: the invitation's role (ADR-0030) is given to the account,
218
+ # new or existing, if it is one an admin may give; admin never.
219
+ from authentik.core.models import Group
220
+ plan = request.context["flow_plan"]
221
+ invite = plan.context.get("invitation")
222
+ user = plan.context.get("pending_user")
223
+ role = (invite.fixed_data or {}).get("paramira_role") if invite else None
224
+ if user is not None and user.pk and role in ("community", "contributor", "editor", "customer"):
225
+ group = Group.objects.filter(name="paramira-web-" + role).first()
226
+ if group is not None:
227
+ user.groups.add(group)
228
+ return True
229
+
230
+ - model: authentik_policies_expression.expressionpolicy
231
+ id: pol-from-invitation
232
+ identifiers: {name: paramira-enrollment-from-invitation}
233
+ attrs:
234
+ expression: |
235
+ # Bound to the step after signing in: someone who came from an
236
+ # invitation link (not from a site's sign-in, which goes back there)
237
+ # goes on to the site's welcome page.
238
+ plan = request.context["flow_plan"]
239
+ return bool(plan.context.get("invitation")) and not plan.context.get("application")
240
+
241
+ # Flows
242
+ - model: authentik_flows.flow
243
+ id: f-enroll
244
+ identifiers: {slug: paramira-enrollment}
245
+ attrs:
246
+ name: paramira-enrollment
247
+ title: Create your Paramira account
248
+ designation: enrollment
249
+ authentication: require_unauthenticated
250
+ - model: authentik_flows.flow
251
+ id: f-link
252
+ identifiers: {slug: paramira-login-link}
253
+ attrs:
254
+ name: paramira-login-link
255
+ title: Sign in to Paramira
256
+ designation: recovery
257
+ authentication: none
258
+ - model: authentik_flows.flow
259
+ id: f-auth
260
+ identifiers: {slug: paramira-authentication}
261
+ attrs:
262
+ name: paramira-authentication
263
+ title: Sign in to Paramira
264
+ designation: authentication
265
+ authentication: none
266
+
267
+ # Stages
268
+ - model: authentik_stages_invitation.invitationstage
269
+ id: s-invitation
270
+ identifiers: {name: paramira-enrollment-invitation}
271
+ attrs:
272
+ continue_flow_without_invitation: !Env [PARAMIRA_SIGNUP_OPEN, false]
273
+ - model: authentik_stages_prompt.promptstage
274
+ id: s-email
275
+ identifiers: {name: paramira-enrollment-email}
276
+ attrs:
277
+ fields: [!KeyOf p-email]
278
+ - model: authentik_stages_deny.denystage
279
+ id: s-suspended
280
+ identifiers: {name: paramira-suspended}
281
+ attrs:
282
+ deny_message: This account is suspended. Write to support@paramira.org if you think it's a mistake.
283
+ - model: authentik_stages_deny.denystage
284
+ id: s-not-invited
285
+ identifiers: {name: paramira-enrollment-not-invited}
286
+ attrs:
287
+ deny_message: This invitation is for another email address. Use the address it was sent to.
288
+ - model: authentik_stages_user_write.userwritestage
289
+ id: s-precreate
290
+ identifiers: {name: paramira-enrollment-create}
291
+ attrs:
292
+ user_creation_mode: always_create
293
+ create_users_as_inactive: true
294
+ create_users_group: !KeyOf g-members
295
+ user_path_template: users/paramira
296
+ - model: authentik_stages_email.emailstage
297
+ id: s-verify
298
+ identifiers: {name: paramira-enrollment-link}
299
+ attrs:
300
+ use_global_settings: true
301
+ token_expiry: minutes=30
302
+ subject: Your Paramira sign-in link
303
+ template: paramira/link.html
304
+ activate_user_on_success: true
305
+ - model: authentik_stages_prompt.promptstage
306
+ id: s-profile
307
+ identifiers: {name: paramira-enrollment-profile}
308
+ attrs:
309
+ fields: [!KeyOf p-username, !KeyOf p-name, !KeyOf p-wallet]
310
+ validation_policies: [!KeyOf pol-own-username]
311
+ - model: authentik_stages_user_write.userwritestage
312
+ id: s-write
313
+ identifiers: {name: paramira-enrollment-save}
314
+ attrs:
315
+ user_creation_mode: never_create
316
+ - model: authentik_stages_user_login.userloginstage
317
+ id: s-login
318
+ identifiers: {name: paramira-login}
319
+ attrs:
320
+ session_duration: days=30
321
+ - model: authentik_stages_redirect.redirectstage
322
+ id: s-to-site
323
+ identifiers: {name: paramira-enrollment-to-site}
324
+ attrs:
325
+ mode: static
326
+ target_static: !Format ["%s/welcome", !Env [PARAMIRA_SITE_URL, "https://paramira.localhost"]]
327
+ - model: authentik_stages_identification.identificationstage
328
+ id: s-identify
329
+ identifiers: {name: paramira-login-identify}
330
+ attrs:
331
+ user_fields: [email, username]
332
+ case_insensitive_matching: true
333
+ pretend_user_exists: true
334
+ show_matched_user: false
335
+ enrollment_flow: !KeyOf f-enroll
336
+ - model: authentik_stages_email.emailstage
337
+ id: s-link
338
+ identifiers: {name: paramira-login-link}
339
+ attrs:
340
+ use_global_settings: true
341
+ token_expiry: minutes=10
342
+ subject: Your Paramira sign-in link
343
+ template: paramira/link.html
344
+ activate_user_on_success: false
345
+ - model: authentik_stages_redirect.redirectstage
346
+ id: s-to-link
347
+ identifiers: {name: paramira-authentication-to-link}
348
+ attrs:
349
+ mode: flow
350
+ target_flow: !KeyOf f-link
351
+ keep_context: true
352
+
353
+ # Sign-up bindings
354
+ - model: authentik_flows.flowstagebinding
355
+ identifiers: {target: !KeyOf f-enroll, stage: !KeyOf s-invitation, order: 5}
356
+ - model: authentik_flows.flowstagebinding
357
+ identifiers: {target: !KeyOf f-enroll, stage: !KeyOf s-email, order: 10}
358
+ - model: authentik_flows.flowstagebinding
359
+ id: b-not-invited
360
+ identifiers: {target: !KeyOf f-enroll, stage: !KeyOf s-not-invited, order: 15}
361
+ attrs: {evaluate_on_plan: false, re_evaluate_policies: true}
362
+ - model: authentik_policies.policybinding
363
+ identifiers: {target: !KeyOf b-not-invited, policy: !KeyOf pol-not-invited-email, order: 0}
364
+ - model: authentik_flows.flowstagebinding
365
+ id: b-precreate
366
+ identifiers: {target: !KeyOf f-enroll, stage: !KeyOf s-precreate, order: 20}
367
+ attrs: {evaluate_on_plan: false, re_evaluate_policies: true}
368
+ - model: authentik_policies.policybinding
369
+ identifiers: {target: !KeyOf b-precreate, policy: !KeyOf pol-new-or-existing, order: 0}
370
+ - model: authentik_flows.flowstagebinding
371
+ id: b-verify
372
+ identifiers: {target: !KeyOf f-enroll, stage: !KeyOf s-verify, order: 30}
373
+ attrs: {evaluate_on_plan: false, re_evaluate_policies: true}
374
+ - model: authentik_policies.policybinding
375
+ identifiers: {target: !KeyOf b-verify, policy: !KeyOf pol-forget-temp-username, order: 0}
376
+ - model: authentik_policies.policybinding
377
+ identifiers: {target: !KeyOf b-verify, policy: !KeyOf pol-people-can-see, order: 1}
378
+ - model: authentik_flows.flowstagebinding
379
+ id: b-enroll-suspended
380
+ identifiers: {target: !KeyOf f-enroll, stage: !KeyOf s-suspended, order: 35}
381
+ attrs: {evaluate_on_plan: false, re_evaluate_policies: true}
382
+ - model: authentik_policies.policybinding
383
+ identifiers: {target: !KeyOf b-enroll-suspended, policy: !KeyOf pol-suspended, order: 0}
384
+ - model: authentik_flows.flowstagebinding
385
+ id: b-profile
386
+ identifiers: {target: !KeyOf f-enroll, stage: !KeyOf s-profile, order: 40}
387
+ attrs: {evaluate_on_plan: false, re_evaluate_policies: true}
388
+ - model: authentik_policies.policybinding
389
+ identifiers: {target: !KeyOf b-profile, policy: !KeyOf pol-new-only, order: 0}
390
+ - model: authentik_flows.flowstagebinding
391
+ id: b-write
392
+ identifiers: {target: !KeyOf f-enroll, stage: !KeyOf s-write, order: 50}
393
+ attrs: {evaluate_on_plan: false, re_evaluate_policies: true}
394
+ - model: authentik_policies.policybinding
395
+ identifiers: {target: !KeyOf b-write, policy: !KeyOf pol-new-only, order: 0}
396
+ - model: authentik_flows.flowstagebinding
397
+ id: b-login
398
+ identifiers: {target: !KeyOf f-enroll, stage: !KeyOf s-login, order: 60}
399
+ attrs: {evaluate_on_plan: false, re_evaluate_policies: true}
400
+ - model: authentik_policies.policybinding
401
+ identifiers: {target: !KeyOf b-login, policy: !KeyOf pol-invited-role, order: 0}
402
+ - model: authentik_policies.policybinding
403
+ identifiers: {target: !KeyOf b-login, policy: !KeyOf pol-people-cannot-delete, order: 1}
404
+ - model: authentik_flows.flowstagebinding
405
+ id: b-to-site
406
+ identifiers: {target: !KeyOf f-enroll, stage: !KeyOf s-to-site, order: 70}
407
+ attrs: {evaluate_on_plan: false, re_evaluate_policies: true}
408
+ - model: authentik_policies.policybinding
409
+ identifiers: {target: !KeyOf b-to-site, policy: !KeyOf pol-from-invitation, order: 0}
410
+
411
+ # Sign-in bindings
412
+ - model: authentik_flows.flowstagebinding
413
+ identifiers: {target: !KeyOf f-link, stage: !KeyOf s-identify, order: 10}
414
+ - model: authentik_flows.flowstagebinding
415
+ identifiers: {target: !KeyOf f-link, stage: !KeyOf s-link, order: 20}
416
+ - model: authentik_flows.flowstagebinding
417
+ id: b-link-suspended
418
+ identifiers: {target: !KeyOf f-link, stage: !KeyOf s-suspended, order: 25}
419
+ attrs: {evaluate_on_plan: false, re_evaluate_policies: true}
420
+ - model: authentik_policies.policybinding
421
+ identifiers: {target: !KeyOf b-link-suspended, policy: !KeyOf pol-suspended, order: 0}
422
+ - model: authentik_flows.flowstagebinding
423
+ identifiers: {target: !KeyOf f-link, stage: !KeyOf s-login, order: 30}
424
+ - model: authentik_flows.flowstagebinding
425
+ identifiers: {target: !KeyOf f-auth, stage: !KeyOf s-to-link, order: 10}
426
+
427
+ # Brand
428
+ - model: authentik_brands.brand
429
+ identifiers: {domain: !Env [PARAMIRA_AUTH_DOMAIN, auth.paramira.localhost]}
430
+ attrs:
431
+ default: false
432
+ branding_title: Paramira
433
+ branding_custom_css: |
434
+ :root { --pf-global--primary-color--100: #2f7d5a; --pf-global--link--Color: #2f7d5a; }
435
+ flow_authentication: !KeyOf f-auth
436
+ flow_recovery: !KeyOf f-link
437
+ flow_invalidation: !Find [authentik_flows.flow, [slug, default-invalidation-flow]]
438
+ flow_user_settings: !Find [authentik_flows.flow, [slug, default-user-settings-flow]]