Skip to content

Commit 054d450

Browse files
scottoharashockey
authored andcommitted
fix: add client_id and client_secret to form when type is request-body (via #4213)
1 parent c5c4e08 commit 054d450

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/core/plugins/auth/actions.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,21 +84,33 @@ export const authorizePassword = ( auth ) => ( { authActions } ) => {
8484
} else {
8585
Object.assign(form, {username}, {password})
8686

87-
if ( passwordType === "query") {
88-
if ( clientId ) {
89-
query.client_id = clientId
90-
}
91-
if ( clientSecret ) {
92-
query.client_secret = clientSecret
93-
}
94-
} else {
95-
headers.Authorization = "Basic " + btoa(clientId + ":" + clientSecret)
87+
switch ( passwordType ) {
88+
case "query":
89+
setClientIdAndSecret(query, clientId, clientSecret)
90+
break
91+
92+
case "request-body":
93+
setClientIdAndSecret(form, clientId, clientSecret)
94+
break
95+
96+
default:
97+
headers.Authorization = "Basic " + btoa(clientId + ":" + clientSecret)
9698
}
9799
}
98100

99101
return authActions.authorizeRequest({ body: buildFormData(form), url: schema.get("tokenUrl"), name, headers, query, auth})
100102
}
101103

104+
function setClientIdAndSecret(target, clientId, clientSecret) {
105+
if ( clientId ) {
106+
Object.assign(target, {client_id: clientId})
107+
}
108+
109+
if ( clientSecret ) {
110+
Object.assign(target, {client_secret: clientSecret})
111+
}
112+
}
113+
102114
export const authorizeApplication = ( auth ) => ( { authActions } ) => {
103115
let { schema, scopes, name, clientId, clientSecret } = auth
104116
let headers = {

0 commit comments

Comments
 (0)