fix(common): oauth2 basic header encoding (#4927)
This commit is contained in:
parent
9e541a8a4b
commit
0c361faeab
1 changed files with 10 additions and 1 deletions
|
|
@ -177,7 +177,10 @@ const getPayloadForViaBasicAuthHeader = (
|
|||
): RelayRequest => {
|
||||
const { clientID, clientSecret, scopes, authEndpoint } = payload
|
||||
|
||||
const basicAuthToken = btoa(`${clientID}:${clientSecret}`)
|
||||
// RFC 6749 Section 2.3.1 states that the client ID and secret should be URL encoded.
|
||||
const encodedClientID = encodeBasicAuthComponent(clientID)
|
||||
const encodedClientSecret = encodeBasicAuthComponent(clientSecret || "")
|
||||
const basicAuthToken = btoa(`${encodedClientID}:${encodedClientSecret}`)
|
||||
|
||||
return {
|
||||
id: Date.now(),
|
||||
|
|
@ -218,3 +221,9 @@ const getPayloadForViaBody = (
|
|||
}),
|
||||
}
|
||||
}
|
||||
|
||||
const encodeBasicAuthComponent = (component: string): string => {
|
||||
// application/x-www-form-urlencoded expects spaces to be encoded as '+', but
|
||||
// encodeURIComponent encodes them as '%20'.
|
||||
return encodeURIComponent(component).replace(/%20/g, "+")
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue