web: fix redirect when accessing authentik URLs authenticated

closes #3174

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-06-30 22:37:29 +02:00
parent b7558ae28c
commit 56fd436e5d
4 changed files with 13 additions and 8 deletions

View File

@ -14,7 +14,9 @@ from authentik.core.views.session import EndSessionView
urlpatterns = [ urlpatterns = [
path( path(
"", "",
login_required(RedirectView.as_view(pattern_name="authentik_core:if-user")), login_required(
RedirectView.as_view(pattern_name="authentik_core:if-user", query_string=True)
),
name="root-redirect", name="root-redirect",
), ),
path( path(

View File

@ -37,7 +37,7 @@ urlpatterns = [
), ),
path( path(
"<slug:application_slug>/end-session/", "<slug:application_slug>/end-session/",
RedirectView.as_view(pattern_name="authentik_core:if-session-end"), RedirectView.as_view(pattern_name="authentik_core:if-session-end", query_string=True),
name="end-session", name="end-session",
), ),
path("<slug:application_slug>/jwks/", JWKSView.as_view(), name="jwks"), path("<slug:application_slug>/jwks/", JWKSView.as_view(), name="jwks"),

View File

@ -43,7 +43,10 @@ export function me(): Promise<SessionUser> {
}, },
}; };
if (ex.response.status === 401 || ex.response.status === 403) { if (ex.response.status === 401 || ex.response.status === 403) {
window.location.assign("/"); const relativeUrl = window.location
.toString()
.substring(window.location.origin.length);
window.location.assign(`/flows/-/default/authentication/?next=${encodeURIComponent(relativeUrl)}`);
} }
return defaultUser; return defaultUser;
}); });

View File

@ -100,6 +100,11 @@ export class AdminInterface extends LitElement {
}); });
}); });
this.version = new AdminApi(DEFAULT_CONFIG).adminVersionRetrieve(); this.version = new AdminApi(DEFAULT_CONFIG).adminVersionRetrieve();
me().then((u) => {
if (!u.user.isSuperuser && u.user.pk > 0) {
window.location.assign("/if/user");
}
});
} }
render(): TemplateResult { render(): TemplateResult {
@ -150,11 +155,6 @@ export class AdminInterface extends LitElement {
} }
renderSidebarItems(): TemplateResult { renderSidebarItems(): TemplateResult {
me().then((u) => {
if (!u.user.isSuperuser) {
window.location.assign("/if/user");
}
});
return html` return html`
${until( ${until(
this.version.then((version) => { this.version.then((version) => {