Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export const Oauth2SettingsSchema = z.object({
),
),
allowedEmails: z.array(z.string()),
allowedGroups: z.array(z.string()),
}),
yandex: z.object({
enabled: z.boolean(),
Expand Down
1 change: 1 addition & 0 deletions prisma/seed/config.seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -797,6 +797,7 @@ async function seedRemnawaveSettings() {
clientSecret: null,
plainDomain: null,
allowedEmails: [],
allowedGroups: [],
},
yandex: {
enabled: false,
Expand Down
29 changes: 27 additions & 2 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,17 @@ export class AuthService {
remnawaveSettings.oauth2Settings.pocketid.clientSecret!,
null,
);
const scopes = ['email', 'profile'];
if (
remnawaveSettings.oauth2Settings.pocketid.allowedGroups &&
remnawaveSettings.oauth2Settings.pocketid.allowedGroups.length > 0
) {
scopes.push('groups');
}
authorizationURL = pocketIdClient.createAuthorizationURL(
`https://${remnawaveSettings.oauth2Settings.pocketid.plainDomain}/authorize`,
state,
['email', 'profile'],
scopes,
);
stateKey = `oauth2:${OAUTH2_PROVIDERS.POCKETID}`;
break;
Expand Down Expand Up @@ -772,12 +779,30 @@ export class AuthService {
return { isAllowed: true, email };
}

if (
remnawaveSettings.oauth2Settings.pocketid.allowedGroups &&
remnawaveSettings.oauth2Settings.pocketid.allowedGroups.length > 0
) {
const userGroups =
'groups' in claims && Array.isArray(claims.groups)
? (claims.groups as string[])
: [];

const hasAllowedGroup = userGroups.some((group) =>
remnawaveSettings.oauth2Settings.pocketid.allowedGroups.includes(group),
);

if (hasAllowedGroup) {
return { isAllowed: true, email };
}
}

await this.emitFailedLoginAttempt(
email,
'–',
ip,
userAgent,
'PocketID email is not in the allowed list and remnawaveClaim is not present.',
'PocketID email/group is not in the allowed list and remnawaveClaim is not present.',
);

return { isAllowed: false, email: null };
Expand Down