Skip to content

Commit

Permalink
Fix mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
pozylon committed Jan 4, 2025
1 parent d65c4fe commit 352b0d1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions examples/keycloak/boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,13 @@ const engine = await startPlatform({
}

const decoded = jwt.decode(req.session.keycloak.id_token);
const { sub, groups, preferred_username } = decoded as {
const { sub, resource_access, preferred_username } = decoded as {
sub: string;
groups: string[];
resource_access: Record<string, { roles: string[] }>;
preferred_username: string;
};

const roles = groups || [];
const roles = resource_access?.['unchained-local']?.roles || [];
const username = preferred_username || `keycloak:${sub}`;
let user = await context.modules.users.findUserByUsername(username);
if (roles.join(':') !== user.roles.join(':')) {
Expand Down Expand Up @@ -133,13 +133,13 @@ app.get(
try {
const accessToken = await this.keycloak.getAccessTokenFromAuthorizationCodeFlow(request);
const decoded = jwt.decode(accessToken.token.id_token);
const { sub, groups, preferred_username } = decoded as {
const { sub, resource_access, preferred_username } = decoded as {
sub: string;
groups: string[];
resource_access: Record<string, { roles: string[] }>;
preferred_username: string;
};

const roles = groups || [];
const roles = resource_access?.['unchained-local']?.roles || [];
const username = preferred_username || `keycloak:${sub}`;
const user = await request.unchainedContext.modules.users.findUserByUsername(username);

Expand Down

0 comments on commit 352b0d1

Please sign in to comment.