Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

fix: url encode UAA oAuth client credentials #26

Merged
merged 1 commit into from
Feb 19, 2020

Conversation

tcdowney
Copy link
Member

@tcdowney tcdowney commented Feb 19, 2020

Although this header was base64 encoded, the oAuth spec requires
that is also be url encoded. This was causing client credentials
that contained special characters (e.g. +) to be rejected by UAA:

{"error":"uaa get token: bad response, code 401: {\"error\":\"unauthorized\",\"error_description\":\"Bad credentials\"}","level":"error","msg":"fetching","time":"2020-02-18T23:49:41Z"}

The client identifier is encoded using the
"application/x-www-form-urlencoded" encoding algorithm per
Appendix B, and the encoded value is used as the username; the client
password is encoded using the same algorithm and used as the
password.

https://tools.ietf.org/html/rfc6749#section-2.3.1

Related:
golang/oauth2#320

Tracker Story:
#171268188

Thanks to @joshuatcasey for helping me make sense of the oAuth spec!

Although this header was base64 encoded, the oAuth spec requires
that is also be url encoded. This was causing client credentials
that contained special characters (e.g. `+`) to be rejected by UAA.

See:
> The client identifier is encoded using the
   "application/x-www-form-urlencoded" encoding algorithm per
   Appendix B, and the encoded value is used as the username; the client
   password is encoded using the same algorithm and used as the
   password.

https://tools.ietf.org/html/rfc6749#section-2.3.1

Related:
golang/oauth2#320

[#171268188](https://www.pivotaltracker.com/story/show/171268188)
Copy link
Contributor

@XanderStrike XanderStrike left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

swag

Copy link
Contributor

@ndhanushkodi ndhanushkodi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

Copy link
Contributor

@dolfolife dolfolife left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@@ -20,12 +21,14 @@ type jsonClient interface {

func (c *Client) GetToken() (string, error) {
reqURL := fmt.Sprintf("%s/oauth/token", c.BaseURL)
bodyString := fmt.Sprintf("client_id=%s&grant_type=client_credentials", c.Name)
bodyString := fmt.Sprintf("grant_type=client_credentials")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we do not need client_id anymore?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The client looks older now, no need to proof with ID.

@ndhanushkodi ndhanushkodi merged commit 3343375 into master Feb 19, 2020
@ndhanushkodi ndhanushkodi deleted the url-encode-uaa-client-creds-171268188 branch February 19, 2020 17:40
routing-ci pushed a commit that referenced this pull request Sep 15, 2020
fix: put CF vars to unique temp dir
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants