Skip to content
Merged
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
5 changes: 4 additions & 1 deletion packages/service-utils/src/core/authorize/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { authorizeClient } from "./client.js";
import { authorizeService } from "./service.js";
import type { AuthorizationResult } from "./types.js";
import { hashKey } from "./utils.js";

export type AuthorizationInput = {
secretKey: string | null;
Expand Down Expand Up @@ -41,7 +42,9 @@ export async function authorize(
cacheOptions?: CacheOptions,
): Promise<AuthorizationResult> {
let teamAndProjectResponse: TeamAndProjectResponse | null = null;
const cacheKey = `key_v2_${authData.clientId ?? authData.secretKeyHash ?? authData.hashedJWT}`;
const cacheKey = hashKey(
`key_v2_:${authData.secretKeyHash}:${authData.hashedJWT}:${authData.clientId}`,
);
// TODO if we have cache options we want to check the cache first
if (cacheOptions) {
try {
Expand Down
5 changes: 5 additions & 0 deletions packages/service-utils/src/core/authorize/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import crypto from "node:crypto";

export const hashKey = (str: string): string => {
return crypto.createHash("sha256").update(str, "utf8").digest("hex");
};
Loading