Skip to content

Commit

Permalink
chore: test fix for prod with keycloak repository
Browse files Browse the repository at this point in the history
  • Loading branch information
brunotot committed Aug 19, 2024
1 parent 146b4c6 commit ab8d297
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export function withSecured(...roles: KeycloakRole[]): RequestHandler[] {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
if (!error.content) {
res.status(500).send({ error });
res?.status(500).send({ error });
return;
}
const typedError = error as ErrorResponse;
const content = typedError.content;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class KeycloakDao {

public async getToken(): Promise<string> {
if (this.token && this.tokenExpiresAt && Date.now() < this.tokenExpiresAt) {
// return this.token;
return this.token;
}

const response = await axios.post(
Expand All @@ -43,7 +43,7 @@ export class KeycloakDao {
);

this.token = response.data.access_token;
this.tokenExpiresAt = Date.now() + response.data.expires_in * 1000 - 60000;
this.tokenExpiresAt = Date.now() + response.data.expires_in * 1000;

return this.token;
}
Expand All @@ -52,17 +52,17 @@ export class KeycloakDao {
const token = await this.getToken();
return {
headers: {
Authorization: `Bearer ${token}`,
Authorization: `bearer ${token}`,
},
} satisfies AxiosRequestConfig;
}

protected auth(): string {
protected auth() {
return new URLSearchParams({
grant_type: "client_credentials",
client_id: this.KEYCLOAK_ADMIN_CLI_ID,
client_secret: this.KEYCLOAK_ADMIN_CLI_SECRET,
}).toString();
grant_type: "client_credentials",
});
}

protected genericEndpoint(path: string, asAdmin: boolean): string {
Expand Down

0 comments on commit ab8d297

Please sign in to comment.