Skip to content

feat: replace auth with keycloak - #295

Draft
m-julio wants to merge 2 commits into
mainfrom
feat/keycloak
Draft

m-julio wants to merge 2 commits into
mainfrom
feat/keycloak

Conversation

@m-julio

@m-julio m-julio commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator
  • Add libs to communicate in oidc with keycloak
  • Delete the LoginPage
  • Wrap Router inside withAuthenticationRequired and add AuthContext
  • Use context to retreive data from token (roles)

@vercel

vercel Bot commented Sep 9, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
new-pyro-platform Error Error Sep 23, 2026 11:29am UTC

@ThbltLmr ThbltLmr left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing that's not super clear to me: who is meant to enforce roles and store users in the end? cause I see there are PRs on the API to add user endpoints? pyronear/pyro-api#657

Comment thread src/context/AuthProvider.tsx Outdated
redirect_uri: appConfig.getConfig().KEYCLOAK_REDIRECT_URI,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
onSigninCallback: (_user: User | undefined): void => {
// Permet de supprimer les éléments d'authent dans l'url (fausse react router)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

little french comment snuck in ;)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice point. I'll change it

const { i18n } = useTranslation();
return (
<AuthProviderOidc {...oidcConfig(i18n.language)}>
<CustomAuthProvider>{children}</CustomAuthProvider>

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with react-oidc-context, but it's surprising that we still need our own child context nested in it 🤔

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use it to hide the config of react oidc context, and provide a few transformed information

Comment thread src/utils/token.ts
if (user) {
accessToken = extractAccessToken(user);
}
return accessToken?.roles ?? [];

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert, but I think when we had keycloak on a project, roles were not directly in user.access_token, they were nested? user.access_token.realm_access.roles I think?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends how you configure your token in keycloak :)

@m-julio

m-julio commented Sep 23, 2026

Copy link
Copy Markdown
Collaborator Author

One thing that's not super clear to me: who is meant to enforce roles and store users in the end? cause I see there are PRs on the API to add user endpoints? pyronear/pyro-api#657

Both should control the role : frontend, to prevent the user to access some functions and backend for security (if api is called directly)
The session is store in keycloak, but the token (renewed often) is stored by the frontend and sent at each call to api

This branch had an error being deployed

1 failed deployment
Preview 4b2459d9 Deployed Sep 23, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants