Skip to content

Commit

Permalink
✨ Configuration de la durée validité du token JWT (MTES-MCT#1391)
Browse files Browse the repository at this point in the history
* ✨ Configuration de la durée validité du token JWT

* 🔒️ Utilisation de cookie de session sécurisé en HTTPS
  • Loading branch information
JulienPavon authored Nov 6, 2023
1 parent df9fce2 commit 0bdd163
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import NextAuth from 'next-auth';
import KeycloakProvider from 'next-auth/providers/keycloak';

const FIFTEEN_MINUTES = 15 * 60;
const ONE_DAY = 24 * 60 * 60;

const handler = NextAuth({
providers: [
KeycloakProvider({
Expand All @@ -11,6 +14,8 @@ const handler = NextAuth({
],
session: {
strategy: 'jwt',
maxAge: ONE_DAY,
updateAge: FIFTEEN_MINUTES,
},
callbacks: {
jwt({ token, account }) {
Expand Down
3 changes: 1 addition & 2 deletions src/infra/keycloak/makeKeycloakAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ export const makeKeycloakAuth = (deps: KeycloakAuthDeps) => {
...(!isLocalEnv && {
cookie: {
secure: true,
httpOnly: true,
},
}),
}),
Expand Down Expand Up @@ -121,7 +120,7 @@ export const makeKeycloakAuth = (deps: KeycloakAuthDeps) => {
logger.error(
`Found user keycloak auth but not user in database for id ${req.kauth?.grant?.access_token?.content?.sub}`,
);
res.redirect('/logout');
res.redirect(routes.LOGOUT_ACTION);
return;
}

Expand Down

0 comments on commit 0bdd163

Please sign in to comment.