From 59e522e714f23e6f27b98eebd588d921876c81b5 Mon Sep 17 00:00:00 2001 From: maximthomas Date: Wed, 18 Nov 2026 10:35:27 +0300 Subject: [PATCH 1/3] [#1221] Characterize userinfo and tokeninfo token transport --- e2e/oauth2/oauth2-test.spec.mjs | 157 +++++++++++++++++++++++++++++++- 1 file changed, 152 insertions(+), 5 deletions(-) diff --git a/e2e/oauth2/oauth2-test.spec.mjs b/e2e/oauth2/oauth2-test.spec.mjs index 54239f9f37..258a3801d7 100644 --- a/e2e/oauth2/oauth2-test.spec.mjs +++ b/e2e/oauth2/oauth2-test.spec.mjs @@ -14,8 +14,12 @@ * Copyright 2026 3A Systems, LLC. */ -import { test, expect } from "@playwright/test"; +import { test, expect, request as apiRequest } from "@playwright/test"; import { OPENAM_BASE, getAdminToken, getAuthToken, PASSWORD, USERNAME } from "../common/openam-commons.mjs"; +import { pkce, sessionContext } from "../common/oauth2-fixtures.mjs"; + +// Traces can capture bearer tokens in request headers, query strings and form bodies. +test.use({ trace: "off", screenshot: "off" }); const REALM = "root"; const CLIENT_ID = "test_client_app"; @@ -138,10 +142,7 @@ async function ensureOAuth2ClientExists(adminToken, request, clientId = CLIENT_I test.beforeAll(async ({ request }) => { const adminToken = await getAdminToken(request) - if (!adminToken) { - test.skip("Skipping: ADMIN_TOKEN not set"); - - } + expect(Boolean(adminToken), "Admin authentication must return a session token").toBe(true); await ensureOAuth2ServiceExists(adminToken, request); await ensureOAuth2ClientExists(adminToken, request); await ensureOAuth2ClientExists(adminToken, request, CONSENT_CLIENT_ID, false); @@ -256,6 +257,152 @@ test.describe("OAuth Service test", () => { }); +test.describe("OAuth2 userinfo and tokeninfo transport", () => { + const TRANSPORT_CLIENT_ID = "test_client_oauth2_b4a"; + let transportAccessToken; + let tokenLifetime; + + test.beforeAll(async ({ request }) => { + const adminToken = await getAdminToken(request); + expect(Boolean(adminToken), "Admin authentication must return a session token").toBe(true); + await ensureOAuth2ClientExists(adminToken, request, TRANSPORT_CLIENT_ID); + + const userToken = await getAuthToken(request, USERNAME, PASSWORD); + expect(Boolean(userToken), "User authentication must return a session token").toBe(true); + const context = await sessionContext(apiRequest, userToken); + try { + const { verifier, challenge } = await pkce(); + const state = "b4a-transport-state"; + const authorize = await context.get(`${OPENAM_BASE}/oauth2/authorize`, { + params: { + response_type: "code", + client_id: TRANSPORT_CLIENT_ID, + redirect_uri: REDIRECT_URI, + scope: SCOPE, + state, + code_challenge: challenge, + code_challenge_method: "S256", + }, + maxRedirects: 0, + }); + expect(authorize.status()).toBe(302); + const location = new URL(authorize.headers()["location"], OPENAM_BASE); + expect(location.searchParams.has("error")).toBe(false); + expect(location.searchParams.get("state")).toBe(state); + const code = location.searchParams.get("code"); + expect(Boolean(code), "Authorization must return a code").toBe(true); + + // This public client authenticates with client_id and PKCE, without Basic authentication. + const response = await context.post(`${OPENAM_BASE}/oauth2/access_token`, { + headers: { Accept: "application/json" }, + form: { + grant_type: "authorization_code", + client_id: TRANSPORT_CLIENT_ID, + code, + redirect_uri: REDIRECT_URI, + code_verifier: verifier, + }, + }); + expect(response.status()).toBe(200); + const tokens = await response.json(); + expect(typeof tokens.access_token).toBe("string"); + expect(Boolean(tokens.access_token), "Token exchange must return an access token").toBe(true); + expect(tokens.token_type).toBe("Bearer"); + expect(Number.isInteger(tokens.expires_in)).toBe(true); + expect(tokens.expires_in).toBeGreaterThan(0); + transportAccessToken = tokens.access_token; + tokenLifetime = tokens.expires_in; + } finally { + await context.dispose(); + } + }); + + test("Get user info with access token in POST form body", async ({ request }) => { + const response = await request.post(`${OPENAM_BASE}/oauth2/userinfo`, { + form: { access_token: transportAccessToken }, + headers: { Accept: "application/json" }, + }); + expect(response.status()).toBe(200); + expect(response.headers()["content-type"]).toBe("application/json;charset=UTF-8"); + const userInfo = await response.json(); + expect(Object.keys(userInfo).sort()).toEqual(["family_name", "name", "sub"]); + expect(userInfo.sub).toBe(USERNAME); + }); + + test("Reject user info request with token in both header and form body", async ({ request }) => { + const response = await request.post(`${OPENAM_BASE}/oauth2/userinfo`, { + form: { access_token: transportAccessToken }, + headers: { Authorization: `Bearer ${transportAccessToken}`, Accept: "application/json" }, + }); + // Current Restlet defect: RFC 6750 section 3.1 requires invalid_request for multiple token transports. + // Target: https://www.rfc-editor.org/rfc/rfc6750.html#section-3.1 + expect(response.status()).toBe(400); + expect(response.headers()["content-type"]).toBe("application/json"); + expect(await response.json()).toEqual({ + error: "server_error", + error_description: "Access Token cannot be provided in both form and header", + }); + }); + + test("Get token info with access token in query parameter", async ({ request }) => { + const response = await request.get(`${OPENAM_BASE}/oauth2/tokeninfo`, { + params: { access_token: transportAccessToken }, + headers: { Accept: "application/json" }, + }); + expect(response.status()).toBe(200); + expect(response.headers()["content-type"]).toBe("application/json"); + const tokenInfo = await response.json(); + expect(Object.keys(tokenInfo).sort()).toEqual([ + "access_token", "client_id", "expires_in", "grant_type", "profile", "realm", "scope", "token_type", + ]); + expect(tokenInfo.access_token === transportAccessToken, "Token info must identify the issued token").toBe(true); + expect(tokenInfo.grant_type).toBe("authorization_code"); + expect(tokenInfo.client_id).toBe(TRANSPORT_CLIENT_ID); + expect(tokenInfo.scope).toEqual([SCOPE]); + expect(tokenInfo.profile).toBe(""); + expect(tokenInfo.realm).toBe("/"); + expect(tokenInfo.token_type).toBe("Bearer"); + expect(Number.isInteger(tokenInfo.expires_in)).toBe(true); + expect(tokenInfo.expires_in).toBeGreaterThan(0); + expect(tokenInfo.expires_in).toBeLessThanOrEqual(tokenLifetime); + }); + + test("Get token info with access token in header", async ({ request }) => { + const response = await request.get(`${OPENAM_BASE}/oauth2/tokeninfo`, { + headers: { Authorization: `Bearer ${transportAccessToken}`, Accept: "application/json" }, + }); + expect(response.status()).toBe(200); + expect(response.headers()["content-type"]).toBe("application/json"); + const tokenInfo = await response.json(); + expect(Object.keys(tokenInfo).sort()).toEqual([ + "access_token", "client_id", "expires_in", "grant_type", "profile", "realm", "scope", "token_type", + ]); + expect(tokenInfo.access_token === transportAccessToken, "Token info must identify the issued token").toBe(true); + expect(tokenInfo.grant_type).toBe("authorization_code"); + expect(tokenInfo.client_id).toBe(TRANSPORT_CLIENT_ID); + expect(tokenInfo.scope).toEqual([SCOPE]); + expect(tokenInfo.profile).toBe(""); + expect(tokenInfo.realm).toBe("/"); + expect(tokenInfo.token_type).toBe("Bearer"); + expect(Number.isInteger(tokenInfo.expires_in)).toBe(true); + expect(tokenInfo.expires_in).toBeGreaterThan(0); + expect(tokenInfo.expires_in).toBeLessThanOrEqual(tokenLifetime); + }); + + test("Reject token info request with token in both header and query parameter", async ({ request }) => { + const response = await request.get(`${OPENAM_BASE}/oauth2/tokeninfo`, { + params: { access_token: transportAccessToken }, + headers: { Authorization: `Bearer ${transportAccessToken}`, Accept: "application/json" }, + }); + expect(response.status()).toBe(400); + expect(response.headers()["content-type"]).toBe("application/json"); + expect(await response.json()).toEqual({ + error: "invalid_request", + error_description: "Access Token cannot be provided in both query and header", + }); + }); +}); + /** * A non-browser client posts its consent decision directly, without ever rendering the consent page, and * submits its own session id as the csrf value. This is the flow documented for headless clients. From ea69082a89b8a4eba22e99d735a6821876be9589 Mon Sep 17 00:00:00 2001 From: maximthomas Date: Wed, 18 Nov 2026 11:12:49 +0300 Subject: [PATCH 2/3] [#1221] Assert endpoint responses before redirects --- e2e/oauth2/oauth2-test.spec.mjs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/e2e/oauth2/oauth2-test.spec.mjs b/e2e/oauth2/oauth2-test.spec.mjs index 258a3801d7..3012c0b7dd 100644 --- a/e2e/oauth2/oauth2-test.spec.mjs +++ b/e2e/oauth2/oauth2-test.spec.mjs @@ -319,6 +319,7 @@ test.describe("OAuth2 userinfo and tokeninfo transport", () => { test("Get user info with access token in POST form body", async ({ request }) => { const response = await request.post(`${OPENAM_BASE}/oauth2/userinfo`, { + maxRedirects: 0, form: { access_token: transportAccessToken }, headers: { Accept: "application/json" }, }); @@ -331,6 +332,7 @@ test.describe("OAuth2 userinfo and tokeninfo transport", () => { test("Reject user info request with token in both header and form body", async ({ request }) => { const response = await request.post(`${OPENAM_BASE}/oauth2/userinfo`, { + maxRedirects: 0, form: { access_token: transportAccessToken }, headers: { Authorization: `Bearer ${transportAccessToken}`, Accept: "application/json" }, }); @@ -346,6 +348,7 @@ test.describe("OAuth2 userinfo and tokeninfo transport", () => { test("Get token info with access token in query parameter", async ({ request }) => { const response = await request.get(`${OPENAM_BASE}/oauth2/tokeninfo`, { + maxRedirects: 0, params: { access_token: transportAccessToken }, headers: { Accept: "application/json" }, }); @@ -369,6 +372,7 @@ test.describe("OAuth2 userinfo and tokeninfo transport", () => { test("Get token info with access token in header", async ({ request }) => { const response = await request.get(`${OPENAM_BASE}/oauth2/tokeninfo`, { + maxRedirects: 0, headers: { Authorization: `Bearer ${transportAccessToken}`, Accept: "application/json" }, }); expect(response.status()).toBe(200); @@ -391,6 +395,7 @@ test.describe("OAuth2 userinfo and tokeninfo transport", () => { test("Reject token info request with token in both header and query parameter", async ({ request }) => { const response = await request.get(`${OPENAM_BASE}/oauth2/tokeninfo`, { + maxRedirects: 0, params: { access_token: transportAccessToken }, headers: { Authorization: `Bearer ${transportAccessToken}`, Accept: "application/json" }, }); From 96917b77859b7661edfe24271fa470687623d79d Mon Sep 17 00:00:00 2001 From: maximthomas Date: Wed, 18 Nov 2026 14:08:40 +0300 Subject: [PATCH 3/3] [#1221] Compare UserInfo claims across token transports --- e2e/oauth2/oauth2-test.spec.mjs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/e2e/oauth2/oauth2-test.spec.mjs b/e2e/oauth2/oauth2-test.spec.mjs index 3012c0b7dd..bbe637d0aa 100644 --- a/e2e/oauth2/oauth2-test.spec.mjs +++ b/e2e/oauth2/oauth2-test.spec.mjs @@ -326,7 +326,12 @@ test.describe("OAuth2 userinfo and tokeninfo transport", () => { expect(response.status()).toBe(200); expect(response.headers()["content-type"]).toBe("application/json;charset=UTF-8"); const userInfo = await response.json(); - expect(Object.keys(userInfo).sort()).toEqual(["family_name", "name", "sub"]); + const bearerResponse = await request.get(`${OPENAM_BASE}/oauth2/userinfo`, { + maxRedirects: 0, + headers: { Authorization: `Bearer ${transportAccessToken}`, Accept: "application/json" }, + }); + expect(bearerResponse.status()).toBe(200); + expect(userInfo).toEqual(await bearerResponse.json()); expect(userInfo.sub).toBe(USERNAME); });