Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

fix(portal): ask the identity provider for the account chooser and hint the tenant domain (#962)

Ramy Barsoum1997d3ea9142
diff --git a/cli/src/services.ts b/cli/src/services.ts
index f35993111..1f4795358 100644
--- a/cli/src/services.ts
+++ b/cli/src/services.ts
@@ -260,6 +260,7 @@ const CATALOG: Record<ServiceName, ServiceDef> = {
"OIDC_JWKS_URI",
"OIDC_SCOPES",
"OIDC_PRINCIPAL_CLAIM",
+ "OIDC_PROMPT",
"AUTH_BROKER_UPSTREAM",
"AUTH_BROKER_PREFIX",
],
diff --git a/plugins/portal/src/index.ts b/plugins/portal/src/index.ts
index 697826c34..9c3faea29 100644
--- a/plugins/portal/src/index.ts
+++ b/plugins/portal/src/index.ts
@@ -27,6 +27,7 @@ import {
verifyIdToken,
type OidcConfig,
type PrincipalRule,
+ hostedDomainHint,
} from "./oidc.ts";
import {
proxyToSurface,
@@ -152,6 +153,8 @@ const OIDC: OidcConfig = {
issuer: process.env.OIDC_ISSUER ?? "https://slack.com",
jwksUri: process.env.OIDC_JWKS_URI ?? "https://slack.com/openid/connect/keys",
expectedTeamId: process.env.PORTAL_EXPECTED_TEAM_ID || undefined,
+ prompt: process.env.OIDC_PROMPT || undefined,
+ hostedDomain: hostedDomainHint(process.env.OIDC_ISSUER ?? "https://slack.com", process.env.OIDC_ALLOWED_EMAIL_DOMAIN),
};
const OIDC_JWKS_CONFIGURED = Boolean(process.env.OIDC_JWKS_URI?.trim());
diff --git a/plugins/portal/src/oidc.ts b/plugins/portal/src/oidc.ts
index 874b37b8a..dbd980f22 100644
--- a/plugins/portal/src/oidc.ts
+++ b/plugins/portal/src/oidc.ts
@@ -14,6 +14,14 @@ export interface OidcConfig {
issuer: string;
jwksUri: string;
expectedTeamId?: string;
+ prompt?: string;
+ hostedDomain?: string;
+}
+
+const GOOGLE_ISSUER = "https://accounts.google.com";
+
+export function hostedDomainHint(issuer: string, allowedEmailDomain: string | undefined): string | undefined {
+ return issuer === GOOGLE_ISSUER && allowedEmailDomain ? allowedEmailDomain : undefined;
}
export function pkcePair(): { verifier: string; challenge: string } {
@@ -32,6 +40,8 @@ export function buildAuthorizeUrl(cfg: OidcConfig, args: { state: string; nonce:
u.searchParams.set("nonce", args.nonce);
u.searchParams.set("code_challenge", args.challenge);
u.searchParams.set("code_challenge_method", "S256");
+ if (cfg.prompt) u.searchParams.set("prompt", cfg.prompt);
+ if (cfg.hostedDomain) u.searchParams.set("hd", cfg.hostedDomain);
return u.toString();
}
diff --git a/plugins/portal/test/oidc.test.ts b/plugins/portal/test/oidc.test.ts
index a52d40886..0239c7d8c 100644
--- a/plugins/portal/test/oidc.test.ts
+++ b/plugins/portal/test/oidc.test.ts
@@ -7,6 +7,7 @@ import {
buildAuthorizeUrl,
exchangeCode,
fetchUserinfo,
+ hostedDomainHint,
resolvePrincipal,
verifyIdToken,
type OidcConfig,
@@ -46,6 +47,29 @@ test("buildAuthorizeUrl carries code+PKCE+state+nonce", () => {
assert.equal(u.searchParams.get("nonce"), "NO");
assert.equal(u.searchParams.get("code_challenge"), "CH");
assert.equal(u.searchParams.get("code_challenge_method"), "S256");
+ assert.equal(u.searchParams.get("prompt"), null);
+ assert.equal(u.searchParams.get("hd"), null);
+});
+
+test("buildAuthorizeUrl forwards prompt and hosted-domain hints when configured", () => {
+ const google: OidcConfig = {
+ ...cfg,
+ authEndpoint: "https://accounts.google.com/o/oauth2/v2/auth",
+ issuer: "https://accounts.google.com",
+ prompt: "select_account",
+ hostedDomain: "example.com",
+ };
+ const u = new URL(buildAuthorizeUrl(google, { state: "ST", nonce: "NO", challenge: "CH" }));
+ assert.equal(u.origin + u.pathname, "https://accounts.google.com/o/oauth2/v2/auth");
+ assert.equal(u.searchParams.get("prompt"), "select_account");
+ assert.equal(u.searchParams.get("hd"), "example.com");
+});
+
+test("hostedDomainHint applies only to the Google issuer with a domain gate", () => {
+ assert.equal(hostedDomainHint("https://accounts.google.com", "example.com"), "example.com");
+ assert.equal(hostedDomainHint("https://accounts.google.com", undefined), undefined);
+ assert.equal(hostedDomainHint("https://accounts.google.com", ""), undefined);
+ assert.equal(hostedDomainHint("https://slack.com", "example.com"), undefined);
});
test("exchangeCode posts client_secret_basic + PKCE verifier and parses the token", async () => {