-
-
Notifications
You must be signed in to change notification settings - Fork 923
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add default app and restrict Signed-off-by: Jens Langhammer <[email protected]> * also pass raw email token for custom email templates Signed-off-by: Jens Langhammer <[email protected]> * revoke access token when user logs out Signed-off-by: Jens Langhammer <[email protected]> * remigrate Signed-off-by: Jens Langhammer <[email protected]> * fix tests Signed-off-by: Jens Langhammer <[email protected]> * add command to change user types Signed-off-by: Jens Langhammer <[email protected]> * add some docs Signed-off-by: Jens Langhammer <[email protected]> * blankable Signed-off-by: Jens Langhammer <[email protected]> * actually fix tests Signed-off-by: Jens Langhammer <[email protected]> * update docs Signed-off-by: Jens Langhammer <[email protected]> --------- Signed-off-by: Jens Langhammer <[email protected]>
- Loading branch information
Showing
20 changed files
with
250 additions
and
60 deletions.
There are no files selected for viewing
This file contains 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
26 changes: 26 additions & 0 deletions
26
authentik/brands/migrations/0007_brand_default_application.py
This file contains 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,26 @@ | ||
# Generated by Django 5.0.6 on 2024-07-04 20:32 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("authentik_brands", "0006_brand_authentik_b_domain_b9b24a_idx_and_more"), | ||
("authentik_core", "0035_alter_group_options_and_more"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="brand", | ||
name="default_application", | ||
field=models.ForeignKey( | ||
default=None, | ||
help_text="When set, external users will be redirected to this application after authenticating.", | ||
null=True, | ||
on_delete=django.db.models.deletion.SET_DEFAULT, | ||
to="authentik_core.application", | ||
), | ||
), | ||
] |
This file contains 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 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,28 @@ | ||
"""Change user type""" | ||
|
||
from authentik.core.models import User, UserTypes | ||
from authentik.tenants.management import TenantCommand | ||
|
||
|
||
class Command(TenantCommand): | ||
"""Change user type""" | ||
|
||
def add_arguments(self, parser): | ||
parser.add_argument("--type", type=str, required=True) | ||
parser.add_argument("--all", action="store_true") | ||
parser.add_argument("usernames", nargs="+", type=str) | ||
|
||
def handle_per_tenant(self, **options): | ||
new_type = UserTypes(options["type"]) | ||
qs = ( | ||
User.objects.exclude_anonymous() | ||
.exclude(type=UserTypes.SERVICE_ACCOUNT) | ||
.exclude(type=UserTypes.INTERNAL_SERVICE_ACCOUNT) | ||
) | ||
if options["usernames"] and options["all"]: | ||
self.stderr.write("--all and usernames specified, only one can be specified") | ||
return | ||
if options["usernames"] and not options["all"]: | ||
qs = qs.filter(username__in=options["usernames"]) | ||
updated = qs.update(type=new_type) | ||
self.stdout.write(f"Updated {updated} users.") |
This file contains 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 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 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 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,15 @@ | ||
from hashlib import sha256 | ||
|
||
from django.contrib.auth.signals import user_logged_out | ||
from django.dispatch import receiver | ||
from django.http import HttpRequest | ||
|
||
from authentik.core.models import User | ||
from authentik.providers.oauth2.models import AccessToken | ||
|
||
|
||
@receiver(user_logged_out) | ||
def user_logged_out_oauth_access_token(sender, request: HttpRequest, user: User, **_): | ||
"""Revoke access tokens upon user logout""" | ||
hashed_session_key = sha256(request.session.session_key.encode("ascii")).hexdigest() | ||
AccessToken.objects.filter(user=user, session_id=hashed_session_key).delete() |
This file contains 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 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 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 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 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 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 |
---|---|---|
|
@@ -136,7 +136,6 @@ def test_oauth_enroll(self): | |
# Wait until we've loaded the user info page | ||
sleep(2) | ||
# Wait until we've logged in | ||
self.wait_for_url(self.if_user_url("/library")) | ||
self.driver.get(self.if_user_url("/settings")) | ||
self.wait_for_url(self.if_user_url()) | ||
|
||
self.assert_user(User(username="example-user", name="test name", email="[email protected]")) |
This file contains 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 |
---|---|---|
|
@@ -155,8 +155,7 @@ def test_oauth_enroll(self): | |
prompt_stage.find_element(By.CSS_SELECTOR, "input[name=username]").send_keys(Keys.ENTER) | ||
|
||
# Wait until we've logged in | ||
self.wait_for_url(self.if_user_url("/library")) | ||
self.driver.get(self.if_user_url("/settings")) | ||
self.wait_for_url(self.if_user_url()) | ||
|
||
self.assert_user(User(username="foo", name="admin", email="[email protected]")) | ||
|
||
|
@@ -191,8 +190,7 @@ def test_oauth_enroll_auth(self): | |
self.driver.find_element(By.CSS_SELECTOR, "button[type=submit]").click() | ||
|
||
# Wait until we've logged in | ||
self.wait_for_url(self.if_user_url("/library")) | ||
self.driver.get(self.if_user_url("/settings")) | ||
self.wait_for_url(self.if_user_url()) | ||
|
||
self.assert_user(User(username="foo", name="admin", email="[email protected]")) | ||
|
||
|
Oops, something went wrong.