Skip to content

Commit

Permalink
chore(tsc): fix noPropertyAccessFromIndexSignature error
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasduteil committed Aug 27, 2024
1 parent 175d6ff commit 416feb7
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 15 deletions.
22 changes: 20 additions & 2 deletions src/config/env.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
// load variable from .env file, only used in local dev env
import "dotenv/config";

declare global {
namespace NodeJS {
interface ProcessEnv {
CONSIDER_ALL_EMAIL_DOMAINS_AS_FREE: "True" | "False";
CONSIDER_ALL_EMAIL_DOMAINS_AS_NON_FREE: "True" | "False";
DISABLE_SECURITY_RESPONSE_HEADERS: "True" | "False";
DISPLAY_TEST_ENV_WARNING: "True" | "False";
DO_NOT_AUTHENTICATE_BROWSER: "True" | "False";
DO_NOT_CHECK_EMAIL_DELIVERABILITY: "True" | "False";
DO_NOT_RATE_LIMIT: "True" | "False";
DO_NOT_SEND_MAIL: "True" | "False";
DO_NOT_USE_ANNUAIRE_EMAILS: "True" | "False";
ENABLE_FIXED_ACR: "True" | "False";
SECURE_COOKIES: "true" | "false";
SYMMETRIC_ENCRYPTION_KEY: string;
}
}
}

export const {
NODE_ENV,
DEPLOY_ENV = "preview",
Expand Down Expand Up @@ -35,8 +54,7 @@ if (!process.env.SYMMETRIC_ENCRYPTION_KEY) {
"The SYMMETRIC_ENCRYPTION_KEY environment variable should be 32 bytes long! Use crypto.randomBytes(32).toString('base64') to generate one.",
);
}
export const SYMMETRIC_ENCRYPTION_KEY: string = process.env
.SYMMETRIC_ENCRYPTION_KEY as string;
export const SYMMETRIC_ENCRYPTION_KEY = process.env.SYMMETRIC_ENCRYPTION_KEY;

export const MONCOMPTEPRO_LABEL = "MonComptePro";
export const MONCOMPTEPRO_IDENTIFIER = new URL(MONCOMPTEPRO_HOST).hostname;
Expand Down
12 changes: 10 additions & 2 deletions src/config/oidc-provider-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { Request } from "express";
import { Configuration } from "oidc-provider";
import { Configuration, type UnknownObject } from "oidc-provider";
import { destroyAuthenticatedSession } from "../managers/session/authenticated";
import epochTime from "../services/epoch-time";
import { findAccount } from "../services/oidc-account-adapter";
import policy from "../services/oidc-policy";
import { renderWithEjsLayout } from "../services/renderer";

//

export interface OIDCContextParams extends UnknownObject {
scope: string;
prompt: "select_organization" | "update_userinfo";
}

export const oidcProviderConfiguration = ({
sessionTtlInSeconds = 14 * 24 * 60 * 60,
shortTokenTtlInSeconds = 10 * 60,
Expand Down Expand Up @@ -85,6 +92,7 @@ export const oidcProviderConfiguration = ({
if (!ctx.oidc.session || !ctx.oidc.client || !ctx.oidc.params) {
return undefined;
}
const oidcContextParams = ctx.oidc.params as OIDCContextParams;
const grantId = ctx.oidc.session.grantIdFor(ctx.oidc.client.clientId);

let grant;
Expand All @@ -111,7 +119,7 @@ export const oidcProviderConfiguration = ({

// event existing grant should be updated, as requested scopes might
// be different
grant.addOIDCScope(ctx.oidc.params.scope as string);
grant.addOIDCScope(oidcContextParams.scope);
await grant.save();
return grant;
},
Expand Down
29 changes: 18 additions & 11 deletions src/services/oidc-policy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import { interactionPolicy } from "oidc-provider";
import { interactionPolicy, type InteractionResults } from "oidc-provider";
import type { OIDCContextParams } from "../config/oidc-provider-configuration";
import { getSelectedOrganizationId } from "../repositories/redis/selected-organization";
import { mustReturnOneOrganizationInPayload } from "./must-return-one-organization-in-payload";

//

interface OidcInteractionResults extends InteractionResults {
select_organization?: boolean;
update_userinfo?: boolean;
}
//

const { Prompt, Check, base } = interactionPolicy;

const policy = base();
Expand All @@ -26,11 +35,9 @@ policy.add(
) &&
!selectedOrganizationId
) {
// @ts-ignore
return Check.REQUEST_PROMPT;
}

// @ts-ignore
return Check.NO_NEED_TO_PROMPT;
},
),
Expand All @@ -47,15 +54,15 @@ policy.add(
"interaction_required",
async (ctx) => {
const { oidc } = ctx;
const oidcContextParams = ctx.oidc.params as OIDCContextParams;
const oidcContextResult = oidc.result as OidcInteractionResults;
if (
ctx.params.prompt === "select_organization" &&
!oidc.result?.select_organization
oidcContextParams.prompt === "select_organization" &&
!oidcContextResult?.select_organization
) {
// @ts-ignore
return Check.REQUEST_PROMPT;
}

// @ts-ignore
return Check.NO_NEED_TO_PROMPT;
},
),
Expand All @@ -72,15 +79,15 @@ policy.add(
"interaction_required",
async (ctx) => {
const { oidc } = ctx;
const oidcContextParams = oidc.params as OIDCContextParams;
const oidcContextResult = oidc.result as OidcInteractionResults;
if (
ctx.params.prompt === "update_userinfo" &&
!oidc.result?.update_userinfo
oidcContextParams.prompt === "update_userinfo" &&
!oidcContextResult?.update_userinfo
) {
// @ts-ignore
return Check.REQUEST_PROMPT;
}

// @ts-ignore
return Check.NO_NEED_TO_PROMPT;
},
),
Expand Down

0 comments on commit 416feb7

Please sign in to comment.