Skip to content

Commit

Permalink
User object should not call userInfo endpoint, fixes #51
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrerojosh committed Apr 29, 2021
1 parent 90de94d commit 1ba4506
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/guards/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
} from '../decorators/unprotected.decorator';
import { KeycloakConnectOptions } from '../interface/keycloak-connect-options.interface';
import { KeycloakLogger } from '../logger';
import { extractRequest } from '../util';
import { extractRequest, parseToken } from '../util';

/**
* An authentication guard. Will return a 401 unauthorized when it is unable to
Expand Down Expand Up @@ -79,7 +79,7 @@ export class AuthGuard implements CanActivate {

if (typeof result === 'string') {
// Attach user info object
request.user = await this.keycloak.grantManager.userInfo(jwt);
request.user = parseToken(jwt);
// Attach raw access token JWT extracted from bearer/cookie
request.accessTokenJWT = jwt;

Expand Down
5 changes: 5 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,8 @@ export const extractRequest = (context: ExecutionContext): [any, any] => {

return [request, response];
};

export const parseToken = (token: string): string => {
const parts = token.split('.');
return JSON.parse(Buffer.from(parts[1], 'base64').toString());
};

0 comments on commit 1ba4506

Please sign in to comment.