Skip to content

Commit 08d812c

Browse files
authored
#14 fix: parse OAuth token form requests
Merged through PR #14; the PR retains the reviewed commit history.
1 parent a37f353 commit 08d812c

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

apps/workspace/server/src/modules/identity/oauth-authorization-router.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { json, Router } from "express";
1+
import { json, Router, urlencoded } from "express"
22
import { ApplicationError } from "../../middleware/errors.js";
33
import type { IdentityModule } from "./identity.service.js";
44
import {
@@ -22,6 +22,7 @@ export function createOAuthAuthorizationRouter(options: {
2222
}): Router {
2323
const router = Router();
2424
router.use(json({ limit: "1mb" }));
25+
router.use(urlencoded({ extended: false, limit: "1mb" }));
2526
const clients = new Map<string, OAuthClient>();
2627
for (const client of options.oauthClients?.clients ?? []) {
2728
clients.set(client.clientId, client);

apps/workspace/test/integration/oauth-authorization.test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,15 +109,15 @@ describe("OAuth authorization", () => {
109109

110110
const token = await fetch(`${origin}/api/auth/token`, {
111111
method: "POST",
112-
headers: { "content-type": "application/json" },
113-
body: JSON.stringify({
112+
headers: { "content-type": "application/x-www-form-urlencoded" },
113+
body: new URLSearchParams({
114114
grant_type: "authorization_code",
115-
code,
115+
code: code ?? "",
116116
client_id: CLIENT_ID,
117117
client_secret: CLIENT_SECRET,
118118
redirect_uri: CALLBACK_URL,
119119
code_verifier: CODE_VERIFIER,
120-
}),
120+
}).toString(),
121121
});
122122
expect(token.status).toBe(200);
123123
const body = (await token.json()) as {

0 commit comments

Comments
 (0)