Repository navigation
website/docs: add docs for source switch expression policy #16878
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
23cbf9b
draft for source switch docs
tanberry e0f6d6d
add python
tanberry 6bb5e44
add sidebar entry
tanberry a8185b0
Update website/docs/customize/policies/expression/source_switch.md
tanberry 685f7aa
Update website/docs/customize/policies/index.md
tanberry b9ddfcd
Update website/docs/customize/policies/working_with_policies.md
tanberry c35ed88
Update website/docs/customize/policies/working_with_policies.md
tanberry 070207d
add sectin about binding the policy
tanberry 667ca35
tweak
tanberry 2fcb1dd
Update website/docs/customize/policies/index.md
tanberry 83a22a5
Update website/docs/customize/policies/working_with_policies.md
tanberry 15562e2
Update website/docs/customize/policies/working_with_policies.md
tanberry a961cfb
Update website/docs/customize/policies/working_with_policies.md
tanberry 044822e
Update website/docs/customize/policies/working_with_policies.md
tanberry 4aa7225
Update website/docs/customize/policies/expression.mdx
tanberry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
website/docs/customize/policies/expression/source_switch.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| --- | ||
| title: Switch which source is used based on email address | ||
| --- | ||
|
|
||
| You can use an expression policy to determine which [source](../../../../users-sources/sources/) (a set of user credentials and data, stored in authentik, Google, GitHub, etc) is used for a particular user, based on the domain of the email address the user enters when they log in and authenticate. | ||
|
|
||
| To switch which source is used for a specific user based on their email domain, you need to 1. and then 2. bind that policy to the appropriate stage. | ||
|
|
||
| ## 1. Create an expression policy | ||
|
|
||
| [Create](../working_with_policies.md#create-a-policy) an expression policy] that does the following: | ||
|
|
||
| 1. Maps the desired source for each user domain. | ||
| 2. Determines the user's domain based on their email address. | ||
| 3. Then "switches" the user to the desired source. | ||
|
|
||
| ## Bind the policy to the stage | ||
|
|
||
| The new expression policy needs to be bound to the stage binding that comes after the Identification stage (or any custom stage that you might have created). For more information read our documentation about [bindings](../../../../add-secure-apps/flows-stages/bindings/), and for instructions to bind a policy, see [Bind a policy to a stage]](../../../../customize/policies/working_with_policies/#bind-a-policy-to-a-stage). | ||
|
|
||
| ## Example expression | ||
|
|
||
| ```python | ||
| # This is a mapping of domains to sources | ||
| # the key is a domain for the user and the value is the `slug` of the source to redirect to | ||
| source_email_map = { | ||
| "foo.bar.com": "entra-foo", | ||
| "bar.baz.com": "entra-bar", | ||
| } | ||
|
|
||
| user_email = request.context["pending_user_identifier"] | ||
|
|
||
| _username, _, domain = user_email.partition("@") | ||
| source = source_email_map.get(domain) | ||
| if not source: | ||
| return True | ||
| plan = request.context.get("flow_plan") | ||
| if not plan: | ||
| return False | ||
| # For OIDC | ||
| # plan.redirect(f"/source/oauth/login/{source}/") | ||
| # For SAML | ||
| plan.redirect(f"/source/saml/{source}") | ||
| return False | ||
| ``` | ||
|
tanberry marked this conversation as resolved.
Resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.