Skip to content

Commit 7b81b4f

Browse files
committed
Handle POST bodies in /authorize
1 parent 85e3cad commit 7b81b4f

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

src/server/auth/handlers/authorize.test.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,8 @@ describe('Authorization Handler', () => {
306306
it('handles POST requests the same as GET', async () => {
307307
const response = await supertest(app)
308308
.post('/authorize')
309-
.query({
309+
.type('form')
310+
.send({
310311
client_id: 'valid-client',
311312
response_type: 'code',
312313
code_challenge: 'challenge123',

src/server/auth/handlers/authorize.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export function authorizationHandler({ provider, rateLimit: rateLimitConfig }: A
3333
// Create a router to apply middleware
3434
const router = express.Router();
3535
router.use(allowedMethods(["GET", "POST"]));
36+
router.use(express.urlencoded({ extended: false }));
3637

3738
// Apply rate limiting unless explicitly disabled
3839
if (rateLimitConfig !== false) {
@@ -53,7 +54,8 @@ export function authorizationHandler({ provider, rateLimit: rateLimitConfig }: A
5354
router.all("/", async (req, res) => {
5455
let client_id, redirect_uri;
5556
try {
56-
({ client_id, redirect_uri } = ClientAuthorizationParamsSchema.parse(req.query));
57+
const data = req.method === 'POST' ? req.body : req.query;
58+
({ client_id, redirect_uri } = ClientAuthorizationParamsSchema.parse(data));
5759
} catch (error) {
5860
res.status(400).end(`Bad Request: ${error}`);
5961
return;
@@ -79,7 +81,8 @@ export function authorizationHandler({ provider, rateLimit: rateLimitConfig }: A
7981

8082
let params;
8183
try {
82-
params = RequestAuthorizationParamsSchema.parse(req.query);
84+
const authData = req.method === 'POST' ? req.body : req.query;
85+
params = RequestAuthorizationParamsSchema.parse(authData);
8386
} catch (error) {
8487
const errorUrl = new URL(redirect_uri);
8588
errorUrl.searchParams.set("error", "invalid_request");

0 commit comments

Comments
 (0)