Skip to content

Commit f056c08

Browse files
authentik-automation[bot]BeryJudominic-rtanberry
authored
website/docs: update flow context ref (cherry-pick #17723 to version-2025.10) (#17732)
website/docs: update flow context ref (#17723) * website/docs: update flow context ref * format * Update website/docs/add-secure-apps/flows-stages/flow/context/index.mdx * Update website/docs/add-secure-apps/flows-stages/flow/context/index.mdx --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Signed-off-by: Jens L. <jens@beryju.org> Co-authored-by: Jens L. <jens@goauthentik.io> Co-authored-by: Dominic R <dominic@sdko.org> Co-authored-by: Tana M Berry <tanamarieberry@yahoo.com>
1 parent 06a6d45 commit f056c08

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

authentik/stages/invitation/stage.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
from authentik.stages.invitation.signals import invitation_used
1212
from authentik.stages.prompt.stage import PLAN_CONTEXT_PROMPT
1313

14-
INVITATION_TOKEN_KEY_CONTEXT = "token" # nosec
15-
INVITATION_TOKEN_KEY = "itoken" # nosec
16-
INVITATION_IN_EFFECT = "invitation_in_effect"
17-
INVITATION = "invitation"
14+
QS_INVITATION_TOKEN_KEY = "itoken" # nosec
15+
PLAN_CONTEXT_INVITATION_TOKEN = "token" # nosec
16+
PLAN_CONTEXT_INVITATION_IN_EFFECT = "invitation_in_effect"
17+
PLAN_CONTEXT_INVITATION = "invitation"
1818

1919

2020
class InvitationStageView(StageView):
@@ -23,13 +23,13 @@ class InvitationStageView(StageView):
2323
def get_token(self) -> str | None:
2424
"""Get token from saved get-arguments or prompt_data"""
2525
# Check for ?token= and ?itoken=
26-
if INVITATION_TOKEN_KEY in self.request.session.get(SESSION_KEY_GET, {}):
27-
return self.request.session[SESSION_KEY_GET][INVITATION_TOKEN_KEY]
28-
if INVITATION_TOKEN_KEY_CONTEXT in self.request.session.get(SESSION_KEY_GET, {}):
29-
return self.request.session[SESSION_KEY_GET][INVITATION_TOKEN_KEY_CONTEXT]
26+
if QS_INVITATION_TOKEN_KEY in self.request.session.get(SESSION_KEY_GET, {}):
27+
return self.request.session[SESSION_KEY_GET][QS_INVITATION_TOKEN_KEY]
28+
if PLAN_CONTEXT_INVITATION_TOKEN in self.request.session.get(SESSION_KEY_GET, {}):
29+
return self.request.session[SESSION_KEY_GET][PLAN_CONTEXT_INVITATION_TOKEN]
3030
# Check for {'token': ''} in the context
31-
if INVITATION_TOKEN_KEY_CONTEXT in self.executor.plan.context.get(PLAN_CONTEXT_PROMPT, {}):
32-
return self.executor.plan.context[PLAN_CONTEXT_PROMPT][INVITATION_TOKEN_KEY_CONTEXT]
31+
if PLAN_CONTEXT_INVITATION_TOKEN in self.executor.plan.context.get(PLAN_CONTEXT_PROMPT, {}):
32+
return self.executor.plan.context[PLAN_CONTEXT_PROMPT][PLAN_CONTEXT_INVITATION_TOKEN]
3333
return None
3434

3535
def get_invite(self) -> Invitation | None:
@@ -60,8 +60,8 @@ def dispatch(self, request: HttpRequest) -> HttpResponse:
6060
return self.executor.stage_ok()
6161
return self.executor.stage_invalid(_("Invalid invite/invite not found"))
6262

63-
self.executor.plan.context[INVITATION_IN_EFFECT] = True
64-
self.executor.plan.context[INVITATION] = invite
63+
self.executor.plan.context[PLAN_CONTEXT_INVITATION_IN_EFFECT] = True
64+
self.executor.plan.context[PLAN_CONTEXT_INVITATION] = invite
6565

6666
context = {}
6767
always_merger.merge(context, self.executor.plan.context.get(PLAN_CONTEXT_PROMPT, {}))

authentik/stages/invitation/tests.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616
from authentik.flows.views.executor import SESSION_KEY_PLAN
1717
from authentik.stages.invitation.models import Invitation, InvitationStage
1818
from authentik.stages.invitation.stage import (
19-
INVITATION_TOKEN_KEY,
20-
INVITATION_TOKEN_KEY_CONTEXT,
19+
PLAN_CONTEXT_INVITATION_TOKEN,
2120
PLAN_CONTEXT_PROMPT,
21+
QS_INVITATION_TOKEN_KEY,
2222
)
2323
from authentik.stages.password import BACKEND_INBUILT
2424
from authentik.stages.password.stage import PLAN_CONTEXT_AUTHENTICATION_BACKEND
@@ -89,7 +89,7 @@ def test_with_invitation_get(self):
8989

9090
with patch("authentik.flows.views.executor.FlowExecutorView.cancel", MagicMock()):
9191
base_url = reverse("authentik_api:flow-executor", kwargs={"flow_slug": self.flow.slug})
92-
args = urlencode({INVITATION_TOKEN_KEY: invite.pk.hex})
92+
args = urlencode({QS_INVITATION_TOKEN_KEY: invite.pk.hex})
9393
response = self.client.get(base_url + f"?query={args}")
9494

9595
session = self.client.session
@@ -114,7 +114,7 @@ def test_invalid_flow(self):
114114

115115
with patch("authentik.flows.views.executor.FlowExecutorView.cancel", MagicMock()):
116116
base_url = reverse("authentik_api:flow-executor", kwargs={"flow_slug": self.flow.slug})
117-
args = urlencode({INVITATION_TOKEN_KEY: invite.pk.hex})
117+
args = urlencode({QS_INVITATION_TOKEN_KEY: invite.pk.hex})
118118
response = self.client.get(base_url + f"?query={args}")
119119

120120
session = self.client.session
@@ -134,7 +134,7 @@ def test_with_invitation_prompt_data(self):
134134
)
135135

136136
plan = FlowPlan(flow_pk=self.flow.pk.hex, bindings=[self.binding], markers=[StageMarker()])
137-
plan.context[PLAN_CONTEXT_PROMPT] = {INVITATION_TOKEN_KEY_CONTEXT: invite.pk.hex}
137+
plan.context[PLAN_CONTEXT_PROMPT] = {PLAN_CONTEXT_INVITATION_TOKEN: invite.pk.hex}
138138
session = self.client.session
139139
session[SESSION_KEY_PLAN] = plan
140140
session.save()

website/docs/add-secure-apps/flows-stages/flow/context/index.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ This section describes the data (the context) that are used in authentik, and pr
2323
Keys prefixed with `goauthentik.io` are used internally by authentik and are subject to change without notice, and should not be modified in policies in most cases.
2424
:::
2525

26+
{/* To update this file, search for `PLAN_CONTEXT_\w+\s=` in the workspace to find all definitions. */}
27+
2628
### Common keys
2729

2830
#### `pending_user` ([User object](../../../../users-sources/user/user_ref.mdx#object-properties))
@@ -201,6 +203,22 @@ Optionally override the email address that the email will be sent to. If not set
201203

202204
If _Show matched user_ is disabled, this key will be set to the user identifier entered by the user in the identification stage.
203205

206+
#### Invitation stage
207+
208+
##### `invitation` (Invitation object)
209+
210+
The invitation used with the invitation stage. When **Continue flow without invitation** is enabled, this may be unset.
211+
212+
If the invitation was single-use, this object may hold a reference to an invitation that no longer exists in the database.
213+
214+
##### `invitation_in_effect` (boolean)
215+
216+
A boolean value that is `True` when an invitation has been used.
217+
218+
##### `token` (string)
219+
220+
This value can be set either via [Prompt data](#prompt_data-dictionary) or via policy to interactively/programmatically choose an invitation.
221+
204222
#### Redirect stage
205223

206224
##### `redirect_stage_target` (string):ak-version[2024.12]

0 commit comments

Comments
 (0)