From e8deeda2ba66cbf80ce134ffc2c1121a0330f85a Mon Sep 17 00:00:00 2001 From: Pierre Leroux Date: Fri, 24 Sep 2021 12:34:32 +0200 Subject: [PATCH] fix: OAuth response body was JSON content-type, must be form-urlencoded as per RFC6749 (PR #1555 Fixes #1554) --- src/main/redux/sagas/auth.ts | 6 ++++-- src/utils/contentType.ts | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/redux/sagas/auth.ts b/src/main/redux/sagas/auth.ts index 392951638..04f05d82a 100644 --- a/src/main/redux/sagas/auth.ts +++ b/src/main/redux/sagas/auth.ts @@ -283,12 +283,14 @@ async function opdsSetAuthCredentials( } const headers = new Headers(); - headers.set("Content-Type", ContentType.Json); + headers.set("Content-Type", ContentType.FormUrlEncoded); + + const body = Object.entries(payload).reduce((pv, [k,v]) => `${pv}${pv ? "&" : pv}${k}=${v}`, ""); const { data: postData } = await httpPost( authenticateUrl, { - body: JSON.stringify(payload), + body, headers, }, async (res) => { diff --git a/src/utils/contentType.ts b/src/utils/contentType.ts index f41a27531..0642ae2a6 100644 --- a/src/utils/contentType.ts +++ b/src/utils/contentType.ts @@ -19,7 +19,7 @@ export enum ContentType { Opds2Pub = "application/opds-publication+json", Opds2AuthVendorV1_0 = "application/vnd.opds.authentication.v1.0+json", OpenSearch = "application/opensearchdescription+xml", - FormUrlEncoded = "application/x-www-form-url-encoded", + FormUrlEncoded = "application/x-www-form-urlencoded", Xhtml = "application/xhtml+xml", Html = "text/html", Epub = "application/epub+zip",