Skip to content

Commit 2043e67

Browse files
author
Benoit Ngo
committed
minors fix (removing deprecated usages), explicite Saml2 return url and adding more logs on authentified process
1 parent a707bf7 commit 2043e67

File tree

11 files changed

+50
-30
lines changed

11 files changed

+50
-30
lines changed

.env.dist

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,12 @@ PHPMYADMIN_ROUTER_RULE="Host(`${PHPMYADMIN_DOMAIN}`)"
3030
APP_SSO_SERVICEPROVIDER_X509CERT="MIICkDCCAfmgAwIBAgIBADANBgkqhkiG9w0BAQ0FADBlMQswCQYDVQQGEwJmcjEOMAwGA1UECAwFUEFSSVMxDDAKBgNVBAoMA1RDTTEaMBgGA1UEAwwRZnJvbnQuc29jb3RlYy5kZXYxDjAMBgNVBAcMBVBBUklTMQwwCgYDVQQLDANUQ00wHhcNMTcwOTA4MTUyNzM0WhcNMTgwOTA4MTUyNzM0WjBlMQswCQYDVQQGEwJmcjEOMAwGA1UECAwFUEFSSVMxDDAKBgNVBAoMA1RDTTEaMBgGA1UEAwwRZnJvbnQuc29jb3RlYy5kZXYxDjAMBgNVBAcMBVBBUklTMQwwCgYDVQQLDANUQ00wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAMKCd0hnMKX40MYR+fZNRqMJjSiDpTPTkV9A0bfQKESZ9esPjNt8Janq+2MGLrm6cRcMXRx8yo/x7pfoCmdiu9D7VNhk69nFsNKH0PQp/jf2+vLPHXgKvlcCFvlaOB/Cvg9UnK9mq83H88LPwvrpaNRl4qDrLS5TTByEIohjFUJrAgMBAAGjUDBOMB0GA1UdDgQWBBSk8/zuzxKBEwpusxRAva7oY7MkrDAfBgNVHSMEGDAWgBSk8/zuzxKBEwpusxRAva7oY7MkrDAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBDQUAA4GBAGlGJPIGYAKKkhW/EAvJbprOAwLvSEansPR8iQlGOq49k/R+mvvTKyQ4DsUglrjbTqA90MZ3S7IG25rPtX6uG2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Oo3cEdB/ksCq3hmtlC/DlLZ/D8CJ+7VuZnS1rR2naQ=="
34-
APP_SSO_IDENTITYPROVIDER_ENTITYID="http://samltest.${BASE_DOMAIN}/simplesaml/saml2/idp/metadata.php"
35-
APP_SSO_IDENTITYPROVIDER_LOGINURL="http://samltest.${BASE_DOMAIN}/simplesaml/saml2/idp/SSOService.php"
36-
APP_SSO_IDENTITYPROVIDER_LOGOUTURL="http://samltest.${BASE_DOMAIN}/simplesaml/saml2/idp/SSOService.php"
33+
APP_SSO_IDENTITYPROVIDER_X509CERT=MIIDXTCCAkWgAwIBAgIJALmVVuDWu4NYMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNVBAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBXaWRnaXRzIFB0eSBMdGQwHhcNMTYxMjMxMTQzNDQ3WhcNNDgwNjI1MTQzNDQ3WjBFMQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAzUCFozgNb1h1M0jzNRSCjhOBnR+uVbVpaWfXYIR+AhWDdEe5ryY+CgavOg8bfLybyzFdehlYdDRgkedEB/GjG8aJw06l0qF4jDOAw0kEygWCu2mcH7XOxRt+YAH3TVHa/Hu1W3WjzkobqqqLQ8gkKWWM27fOgAZ6GieaJBN6VBSMMcPey3HWLBmc+TYJmv1dbaO2jHhKh8pfKw0W12VM8P1PIO8gv4Phu/uuJYieBWKixBEyy0lHjyixYFCR12xdh4CA47q958ZRGnnDUGFVE1QhgRacJCOZ9bd5t9mr8KLaVBYTCJo5ERE8jymab5dPqe5qKfJsCZiqWglbjUo9twIDAQABo1AwTjAdBgNVHQ4EFgQUxpuwcs/CYQOyui+r1G+3KxBNhxkwHwYDVR0jBBgwFoAUxpuwcs/CYQOyui+r1G+3KxBNhxkwDAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQsFAAOCAQEAAiWUKs/2x/viNCKi3Y6blEuCtAGhzOOZ9EjrvJ8+COH3Rag3tVBWrcBZ3/uhhPq5gy9lqw4OkvEws99/5jFsX1FJ6MKBgqfuy7yh5s1YfM0ANHYczMmYpZeAcQf2CGAaVfwTTfSlzNLsF2lW/ly7yapFzlYSJLGoVE+OHEu8g5SlNACUEfkXw+5Eghh+KzlIN7R6Q7r2ixWNFBC/jWf7NKUfJyX8qIG5md1YUeT6GBW9Bm2/1/RiO24JTaYlfLdKK9TYb8sG5B+OLab2DImG99CJ25RkAcSobWNF5zD0O6lgOo3cEdB/ksCq3hmtlC/DlLZ/D8CJ+7VuZnS1rR2naQ==
34+
APP_SSO_IDENTITYPROVIDER_ENTITYID=${PROTOCOL}://samltest.${BASE_DOMAIN}/simplesaml/saml2/idp/metadata.php
35+
APP_SSO_IDENTITYPROVIDER_LOGINURL=${PROTOCOL}://samltest.${BASE_DOMAIN}/simplesaml/saml2/idp/SSOService.php
36+
APP_SSO_IDENTITYPROVIDER_LOGOUTURL=${PROTOCOL}://samltest.${BASE_DOMAIN}/simplesaml/saml2/idp/SSOService.php
3737

3838
###> symfony/mailer ###
3939
MAILER_DSN=smtp://mail:1025
4040
MAIL_HOST=admin@mail.com
41+
###< symfony/mailer ###

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ restart: down up ## Soft Restart
8888
.PHONY: frestart
8989
frestart: fdown fup ## Hard restart
9090

91+
92+
.PHONY: fbuild
93+
fbuild: ;\
94+
docker compose build --no-cache
95+
9196
.PHONY: stop-front
9297
stop-front: sync-env ## stop front container
9398
DOCKER_BUILDKIT=1 docker compose stop front

apps/back/config/services.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ services:
6363
class: App\Authenticator\Saml2Authenticator
6464
arguments:
6565
$checkPath: 'api_login_saml2'
66+
$returnTo: "%app.url.base%/api/1.0/auth/sso/saml2/login"
6667

6768

6869
OneLogin\Saml2\Auth:

apps/back/src/Authenticator/Saml2Authenticator.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
namespace App\Authenticator;
66

7-
use App\Exception\SsoConsumerAuthNException;
87
use App\Exception\SsoConsumerException;
98
use OneLogin\Saml2\Auth;
109
use Symfony\Component\HttpFoundation\JsonResponse;
@@ -27,6 +26,8 @@ public function __construct(
2726
private readonly HttpUtils $httpUtils,
2827
private readonly string $checkPath,
2928
private readonly Auth $auth,
29+
private readonly string $returnTo,
30+
private readonly \Psr\Log\LoggerInterface $logger,
3031
) {
3132
}
3233

@@ -43,12 +44,8 @@ public function supports(Request $request): bool|null
4344
public function authenticate(Request $request): Passport
4445
{
4546
$session = $request->getSession();
46-
$authNRequestId = $session->get('AuthNRequestID');
47-
if (! \is_string($authNRequestId)) {
48-
throw new SsoConsumerAuthNException();
49-
}
50-
51-
$auth = $this->auth;
47+
$authNRequestId = $session->get('AuthNRequestID', null);
48+
$auth = $this->auth;
5249
$auth->setStrict(false);
5350
$auth->processResponse($authNRequestId);
5451
$errors = $auth->getErrors();
@@ -97,11 +94,13 @@ public function onAuthenticationFailure(Request $request, AuthenticationExceptio
9794
/** @inheritDoc */
9895
public function start(Request $request, AuthenticationException|null $authException = null)
9996
{
100-
$session = $request->getSession();
101-
$auth = $this->auth;
102-
$url = $auth->login(null, [], false, false, true);
97+
$session = $request->getSession();
98+
$this->logger->debug('Starting auth');
99+
$auth = $this->auth;
100+
$url = $auth->login($this->returnTo, [], false, false, true);
103101
$authNRequestId = $auth->getLastRequestID();
104102
$session->set('AuthNRequestID', $authNRequestId);
103+
$this->logger->debug("Need redirect to $url");
105104

106105
return new JsonResponse(['url' => $url], Response::HTTP_UNAUTHORIZED);
107106
}

apps/front/nuxt.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default defineNuxtConfig({
1212
// @see https://getbootstrap.com/docs/5.0/getting-started/introduction/#starter-template
1313
charset: "utf-8",
1414
viewport: "width=device-width, initial-scale=1",
15-
title: "Boilerplate TCM v2",
15+
title: "Boilerplate SF - Nuxt",
1616
meta: [
1717
// <meta name="description" content="My amazing site">
1818
// { name: 'description', content: 'My amazing site.' }

apps/front/src/app.vue

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<div>
33
<NuxtErrorBoundary @error="mHandleError">
4-
<NuxtLayout v-if="!isPendingAuth || authStore.isAuthenticated">
4+
<NuxtLayout v-if="shouldRender">
55
<NuxtPage />
66
</NuxtLayout>
77
</NuxtErrorBoundary>
@@ -15,19 +15,28 @@ const authStore = useAuthUser();
1515
1616
const route = useRoute();
1717
18-
const mHandleError = (e: unknown) => {
18+
const mHandleError = (e: any) => {
1919
logger.error("Primary error boundary", e);
2020
};
21-
const isPendingAuth = computed(() => authStore.isPending);
21+
const shouldRender = computed(
22+
() => !authStore.isPending || authStore.isAuthenticated
23+
);
2224
// Doing this here instead than in the middleware allow reactivity on the auth user
2325
watchEffect(async () => {
24-
if (isPendingAuth.value) {
26+
logger.info("pending");
27+
if (authStore.isPending) {
2528
return;
2629
}
30+
logger.info("resolved pending");
2731
const shouldRedirectToLogin =
2832
!authStore.isAuthenticated &&
2933
authStore.authUrl &&
3034
route.name !== "auth-login";
35+
logger.info("shouldRedirectToLogin");
36+
logger.info(authStore.isAuthenticated);
37+
logger.info(authStore.authUrl);
38+
logger.info(route.name);
39+
logger.info(shouldRedirectToLogin);
3140
if (shouldRedirectToLogin) {
3241
await navigateTo(authStore.authUrl, { external: true });
3342
}
@@ -38,3 +47,4 @@ watchEffect(async () => {
3847
}
3948
});
4049
</script>
50+
cd

apps/front/src/middleware/auth.global.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export default defineNuxtRouteMiddleware(async () => {
55
// We refresh the data information
66
// If the syncMe result in a 401, the component RedirectToLogin will be triggered,
77
// so no need to wait the sync
8+
logger.info("------ in middleware");
89
const mePromise = authStore.syncMe();
910
/**
1011
* We still wait if the user is not authenticated because that may mean

apps/front/src/plugins/appFetch.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ export default defineNuxtPlugin(() => {
99
const event = useRequestEvent();
1010
const headers: {
1111
[key: string]: string;
12-
} = useRequestHeaders(["cookie"]) as {
13-
[key: string]: string;
12+
} = {
13+
...(useRequestHeaders(["cookie"]) as {
14+
[key: string]: string;
15+
}),
16+
...{
17+
accept: "application/json",
18+
},
1419
};
15-
1620
const handleException = (e: any) => {
1721
logger.error("An error hapenned during an API call");
1822
logger.error(e);
@@ -21,10 +25,9 @@ export default defineNuxtPlugin(() => {
2125
logger.error("401 error, removing authentication informations");
2226
store.resetAuth();
2327
}
24-
// HERE the bug
2528
const cookies = e.response.headers.get("set-cookie") || "";
2629
if (process.server && cookies) {
27-
event.res.setHeader("set-cookie", cookies);
30+
event.node.res.setHeader("set-cookie", cookies);
2831
}
2932
throw e;
3033
};
@@ -40,7 +43,7 @@ export default defineNuxtPlugin(() => {
4043

4144
const cookies = res.headers.get("set-cookie") || "";
4245
if (process.server && cookies) {
43-
event.res.setHeader("set-cookie", cookies);
46+
event.node.res.setHeader("set-cookie", cookies);
4447
}
4548
return res;
4649
};
@@ -57,7 +60,7 @@ export default defineNuxtPlugin(() => {
5760

5861
const cookies = res.headers.get("set-cookie") || "";
5962
if (process.server && cookies) {
60-
event.res.setHeader("set-cookie", cookies);
63+
event.node.res.setHeader("set-cookie", cookies);
6164
}
6265
return res._data;
6366
};

apps/front/src/server/api/[...].ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export default defineEventHandler(async (event: H3Event) => {
3333
headers: {
3434
host: target.host,
3535
},
36-
cookiePathRewrite: {
37-
"/*": "/",
36+
fetchOptions: {
37+
redirect: "manual",
3838
},
3939
});
4040
return ret;

apps/front/src/store/auth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ export const useAuthUser = defineStore({
5656
if (this.isPending) {
5757
return;
5858
}
59+
this.startPending();
5960
// Our session is based on the PHPSESSID cookie
6061
const me = useMe();
6162
try {
62-
this.startPending();
6363
const authUser = await me();
6464
this.setAuthUser(authUser);
6565
this.endPending();

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ services:
4747
working_dir: /home/node/app
4848
environment:
4949
# This is used only per the proxy
50-
NUXT_API_URL: http://${API_DOMAIN}/
50+
- NUXT_API_URL=${PROTOCOL}://${API_DOMAIN}/
5151
proxy:
5252
image: traefik:3.0
5353
container_name: tcm_proxy

0 commit comments

Comments
 (0)