Skip to content

Commit

Permalink
fix: add client_id and client_secret to form when type is request-body (
Browse files Browse the repository at this point in the history
  • Loading branch information
scottohara committed Sep 10, 2018
1 parent 54153dd commit 152e1c9
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions src/core/plugins/auth/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,21 +83,33 @@ export const authorizePassword = ( auth ) => ( { authActions } ) => {
} else {
Object.assign(form, {username}, {password})

if ( passwordType === "query") {
if ( clientId ) {
query.client_id = clientId
}
if ( clientSecret ) {
query.client_secret = clientSecret
}
} else {
headers.Authorization = "Basic " + btoa(clientId + ":" + clientSecret)
switch ( passwordType ) {
case "query":
setClientIdAndSecret(query, clientId, clientSecret)
break

case "request-body":
setClientIdAndSecret(form, clientId, clientSecret)
break

default:
headers.Authorization = "Basic " + btoa(clientId + ":" + clientSecret)
}
}

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

function setClientIdAndSecret(target, clientId, clientSecret) {
if ( clientId ) {
Object.assign(target, {client_id: clientId})
}

if ( clientSecret ) {
Object.assign(target, {client_secret: clientSecret})
}
}

export const authorizeApplication = ( auth ) => ( { authActions } ) => {
let { schema, scopes, name, clientId, clientSecret } = auth
let headers = {
Expand Down

0 comments on commit 152e1c9

Please sign in to comment.