Skip to content

Commit

Permalink
chore: clean up jwk secret
Browse files Browse the repository at this point in the history
  • Loading branch information
naftis committed Feb 5, 2025
1 parent 86f8a67 commit d3f272a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
File renamed without changes.
4 changes: 4 additions & 0 deletions packages/esignet-mock/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { cleanEnv, port, str, url } from "envalid";
import { readFileSync } from "fs";

export const env = cleanEnv(process.env, {
PORT: port({ default: 20260 }),
HOST: str({ default: "0.0.0.0", devDefault: "localhost" }),
CLIENT_URL: url({ devDefault: "http://localhost:3000" }),
OIDP_CLIENT_PRIVATE_KEY_PATH: str({
devDefault: "../../certs/esignet-jwk.txt",
}),
});
10 changes: 5 additions & 5 deletions packages/esignet-mock/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ import path from "path";
import fastifyStatic from "@fastify/static";
import formbody from "@fastify/formbody";
import * as jose from "jose";
import { readFileSync } from "fs";
import { readFileSync } from "node:fs";
import { join } from "path";
import casual from "casual";

const app = Fastify({ logger: true });

const JWT_ALG = "RS256";
const JWT_EXPIRATION_TIME = "1h";
const OIDP_CLIENT_PRIVATE_KEY = readFileSync(
env.OIDP_CLIENT_PRIVATE_KEY_PATH,
).toString();

const generateSignedJwt = async (userInfo: OIDPUserInfo) => {
const header = {
alg: JWT_ALG,
typ: "JWT",
};

const decodeKey = Buffer.from(
readFileSync(join(__dirname, "./dev-secrets/jwk.txt")).toString(),
"base64",
)?.toString();
const decodeKey = Buffer.from(OIDP_CLIENT_PRIVATE_KEY, "base64").toString();
const jwkObject = JSON.parse(decodeKey);
const privateKey = await jose.importJWK(jwkObject, JWT_ALG);

Expand Down
9 changes: 3 additions & 6 deletions packages/mosip-api/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { cleanEnv, str, port, url } from "envalid";
import { readFileSync } from "fs";
import { join } from "path";
import { readFileSync } from "node:fs";

export const env = cleanEnv(process.env, {
PORT: port({ default: 2024 }),
Expand All @@ -27,10 +26,8 @@ export const env = cleanEnv(process.env, {
}),
ESIGNET_TOKEN_URL: url({ devDefault: "http://localhost:20260/oauth/token" }),
OIDP_JWT_AUD_CLAIM: str({ devDefault: undefined }),
OIDP_CLIENT_PRIVATE_KEY: str({
devDefault: readFileSync(
join(__dirname, "./dev-secrets/jwk.txt"),
).toString(),
OIDP_CLIENT_PRIVATE_KEY_PATH: str({
devDefault: "../../certs/esignet-jwk.txt",
}),

// NOTE: Following files and credentials are generally created by MOSIP and their assistance.
Expand Down
10 changes: 5 additions & 5 deletions packages/mosip-api/src/esignet-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ import * as jose from "jose";
import { isValid, format, Locale, parse } from "date-fns";
import { enGB } from "date-fns/locale/en-GB";
import { fr } from "date-fns/locale/fr";
import fs from "node:fs";

const OIDP_CLIENT_PRIVATE_KEY = fs
.readFileSync(env.OIDP_CLIENT_PRIVATE_KEY_PATH)
.toString();
export const locales: Record<string, Locale> = { en: enGB, fr };

type OIDPUserAddress = {
Expand Down Expand Up @@ -91,11 +95,7 @@ const generateSignedJwt = async (clientId: string) => {
aud: env.OIDP_JWT_AUD_CLAIM,
};

const decodeKey = Buffer.from(
env.OIDP_CLIENT_PRIVATE_KEY!,
"base64",
)?.toString();

const decodeKey = Buffer.from(OIDP_CLIENT_PRIVATE_KEY, "base64")?.toString();
const jwkObject = JSON.parse(decodeKey);
const privateKey = await jose.importJWK(jwkObject, JWT_ALG);

Expand Down

0 comments on commit d3f272a

Please sign in to comment.