feat: add environment variable to overwrite oidc scopes

This commit is contained in:
Meier Lukas
2024-02-18 11:51:26 +01:00
parent 46a57c1cf2
commit 34ef216f3f
2 changed files with 40 additions and 30 deletions

View File

@@ -20,13 +20,17 @@ const provider: OAuthConfig<Profile> = {
clientId: env.AUTH_OIDC_CLIENT_ID,
clientSecret: env.AUTH_OIDC_CLIENT_SECRET,
wellKnown: `${env.AUTH_OIDC_URI}/.well-known/openid-configuration`,
authorization: { params: { scope: 'openid email profile groups' } },
authorization: { params: { scope: env.AUTH_OIDC_SCOPE_OVERWRITE } },
idToken: true,
async profile(profile) {
const user = await adapter.getUserByEmail!(profile.email);
const isAdmin = profile.groups.includes(env.AUTH_OIDC_ADMIN_GROUP);
const isOwner = profile.groups.includes(env.AUTH_OIDC_OWNER_GROUP);
if (!profile.groups) {
Consola.warn('no groups found in profile of oidc user');
}
const isAdmin = profile.groups?.includes(env.AUTH_OIDC_ADMIN_GROUP);
const isOwner = profile.groups?.includes(env.AUTH_OIDC_OWNER_GROUP);
// check for role update
if (user && (user.isAdmin != isAdmin || user.isOwner != isOwner)) {