Skip to content

Commit

Permalink
fix: only return user groups if it is explicitly requested
Browse files Browse the repository at this point in the history
  • Loading branch information
stonith404 committed Oct 2, 2024
1 parent 365734e commit a4a90a1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ You may need the following information:
- **Certificate URL**: `https://<your-domain>/.well-known/jwks.json`
- **OIDC Discovery URL**: `https://<your-domain>/.well-known/openid-configuration`
- **PKCE**: `false` as this is not supported yet.
- **Scopes**: At least `openid email`. Optionally you can add `profile` and `groups`.

### Proxy Services with Pocket ID

Expand Down
16 changes: 9 additions & 7 deletions backend/internal/service/oidc_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,20 +308,22 @@ func (s *OidcService) GetUserClaimsForClient(userID string, clientID string) (ma
user := authorizedOidcClient.User
scope := authorizedOidcClient.Scope

userGroups := make([]string, len(user.UserGroups))
for i, group := range user.UserGroups {
userGroups[i] = group.Name
}

claims := map[string]interface{}{
"sub": user.ID,
"groups": userGroups,
"sub": user.ID,
}

if strings.Contains(scope, "email") {
claims["email"] = user.Email
}

if strings.Contains(scope, "groups") {
userGroups := make([]string, len(user.UserGroups))
for i, group := range user.UserGroups {
userGroups[i] = group.Name
}
claims["groups"] = userGroups
}

profileClaims := map[string]interface{}{
"given_name": user.FirstName,
"family_name": user.LastName,
Expand Down
9 changes: 8 additions & 1 deletion frontend/src/routes/authorize/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { getWebauthnErrorMessage } from '$lib/utils/error-util';
import { startAuthentication } from '@simplewebauthn/browser';
import { AxiosError } from 'axios';
import { LucideMail, LucideUser } from 'lucide-svelte';
import { LucideMail, LucideUser, LucideUsers } from 'lucide-svelte';
import { slide } from 'svelte/transition';
import type { PageData } from './$types';
import ClientProviderImages from './components/client-provider-images.svelte';
Expand Down Expand Up @@ -113,6 +113,13 @@
description="View your profile information"
/>
{/if}
{#if scope!.includes('groups')}
<ScopeItem
icon={LucideUsers}
name="Groups"
description="View the groups you are a member of"
/>
{/if}
</div>
</Card.Content>
</Card.Root>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<div class="w-full">
<FormInput
label="Name"
description={`Name that will be in the "userGroup" claim`}
description={`Name that will be in the "groups" claim`}
bind:input={$inputs.name}
onInput={onNameInput}
/>
Expand Down

0 comments on commit a4a90a1

Please sign in to comment.