Skip to content

Commit

Permalink
✨ [#390] Make it possible to redirect to frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
SilviaAmAm committed Oct 11, 2024
1 parent dbee12b commit 3a6d8ed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
7 changes: 5 additions & 2 deletions backend/dotenv.dev.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ DISABLE_2FA=yes
ALLOWED_HOSTS=localhost
CORS_ALLOWED_ORIGINS=http://localhost:8000,http://localhost:3000
CSRF_TRUSTED_ORIGINS=http://localhost:3000
CSRF_COOKIE_SAMESITE='None'
CSRF_COOKIE_SAMESITE='Lax'
CSRF_COOKIE_SECURE=False

SESSION_COOKIE_SAMESITE='None'
SESSION_COOKIE_SAMESITE='Lax'
SESSION_COOKIE_SECURE=False

# For OIDC
OIDC_REDIRECT_ALLOWED_HOSTS=localhost:3000

# For openzaak being slow
REQUESTS_READ_TIMEOUT=5000

Expand Down
3 changes: 3 additions & 0 deletions backend/src/openarchiefbeheer/conf/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,3 +633,6 @@
#
OIDC_AUTHENTICATE_CLASS = "mozilla_django_oidc_db.views.OIDCAuthenticationRequestView"
OIDC_CALLBACK_CLASS = "mozilla_django_oidc_db.views.OIDCCallbackView"
OIDC_REDIRECT_ALLOWED_HOSTS = config(
"OIDC_REDIRECT_ALLOWED_HOSTS", default="", split=True
)
16 changes: 13 additions & 3 deletions frontend/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@ export type LoginProps = React.ComponentProps<"main"> & {
// Props here.
};

/*
* Add the redirect URL to the callback URL
*/
const makeRedirectUrl = (oidcLoginUrl: string) => {
const currentUrl = new URL(window.location.href);
const redirectUrl = new URL("/", currentUrl);
const loginUrl = new URL(oidcLoginUrl);
loginUrl.searchParams.set("next", redirectUrl.href);

return loginUrl.href;
};

/**
* Login page
*/
Expand Down Expand Up @@ -49,12 +61,10 @@ export function LoginPage({ ...props }: LoginProps) {

const oidcProps: Partial<LoginTemplateProps> = {};
if (oidc?.enabled) {
oidcProps.urlOidcLogin = oidc.loginUrl;
oidcProps.urlOidcLogin = makeRedirectUrl(oidc.loginUrl);
oidcProps.labelOidcLogin = "Organisatie login";
}

console.log(oidc, oidcProps, props);

return (
<LoginTemplate
slotPrimaryNavigation={<></>} // FIXME: Should be easier to override
Expand Down

0 comments on commit 3a6d8ed

Please sign in to comment.