Skip to content
This repository has been archived by the owner on Jan 24, 2019. It is now read-only.

Pass the access token to the upstream server #80

Merged
merged 2 commits into from
Apr 3, 2015

Conversation

mbland
Copy link
Contributor

@mbland mbland commented Apr 3, 2015

@jehiah We're looking to allow other services that accept the access_token to be integrated into the 18F Hub per 18F/hub#241. This PR accomplishes this by encoding the access_token in the auth cookie and unpacking it as the X-Forwarded-Access-Token header for upstream requests. The changes maintain backward compatibility with the original cookie format, but I'm happy to entertain other notions or refactor the code.

@dhcole @afeld @adelevie @yozlet @jackiekazil I've actually got our internal Hub running successfully with these changes to the google_auth_proxy and the changes from 18F/hub#241. Just need to merge them to make them official.

I also included a commit to update TestNewReverseProxy(). Without this change, the test will fail when run without an Internet connection. @jehiah I can split that commit out into a separate PR if you prefer.

This reflects the apparent intent of TestNewReverseProxy(). Without this
change, the test will fail when run without an Internet connection.
@mbland mbland changed the title Pass the access token to the upstream client Pass the access token to the upstream server Apr 3, 2015
payload := ""
switch url.Path {
case "/oauth/token":
payload = "{\"access_token\": \"my_auth_token\"}"
Copy link
Member

Choose a reason for hiding this comment

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

Can you backtick this string so it's a little easier to read?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

@mbland
Copy link
Contributor Author

mbland commented Apr 3, 2015

@jehiah I've just pushed changes to set pass_access_token to false by default and to encrypt the access token in the cookie. Confirmed that this is working as advertised on our internal system, in addition to continuing to pass the tests. PTAL?

@jehiah
Copy link
Member

jehiah commented Apr 3, 2015

PTAL? that's a new acronym for me

Changes look good. Let's just error if the cookie secret is <32 char and you enabled passing the access token instead of padding with spaces.

@mbland
Copy link
Contributor Author

mbland commented Apr 3, 2015

Ah, PTAL == Please Take Another Look. :-)

Just pushed a new commit with the changes you asked for. (Actually, the AES cipher isn't created if the cookie_secret isn't exactly 16, 24, or 32 bytes per aes.NewCipher.)

@@ -405,7 +419,17 @@ func (p *OauthProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
// set cookie, or deny
if p.Validator(email) {
log.Printf("%s authenticating %s completed", remoteAddr, email)
p.SetCookie(rw, req, email)
if p.PassAccessToken {
access_token, err = encodeAccessToken(p.AesCipher, access_token)
Copy link
Member

Choose a reason for hiding this comment

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

I think that on the validating request this leaves an encoded access token to be passed in the header because we are re-using this variable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like we always return when we hit this case, but I'll make it a new variable to be on the safe side.

Copy link
Member

Choose a reason for hiding this comment

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

oh duh. i missed that redirect line in looking at the changes. all good here then.

@jehiah
Copy link
Member

jehiah commented Apr 3, 2015

Looks good aside from those two small details. Once you've handled those go ahead and squash the commits in this branch down.

This is accomplished by encoding the access_token in the auth cookie and
unpacking it as the X-Forwarded-Access-Token header for upstream requests.
@mbland mbland force-pushed the pass-access-token branch from 236a753 to ad3c9a8 Compare April 3, 2015 19:32
@mbland
Copy link
Contributor Author

mbland commented Apr 3, 2015

Created a new encoded_token variable and cleared access_token to be safe; wrapped the cipher creation in a pass_access_token case and made an invalid cookie_secret size a fatal error; and squashed everything (except the unrelated test fix) down to a single commit.

@jehiah
Copy link
Member

jehiah commented Apr 3, 2015

awesome!

jehiah added a commit that referenced this pull request Apr 3, 2015
Pass the access token to the upstream server
@jehiah jehiah merged commit 864d478 into bitly:master Apr 3, 2015
@mbland
Copy link
Contributor Author

mbland commented Apr 3, 2015

Sweeet, thanks, @jehiah! Appreciate the thoughtful and timely review.

@mbland mbland deleted the pass-access-token branch April 3, 2015 20:12
jehiah added a commit that referenced this pull request Apr 7, 2015
Refactor pass_access_token changes from #80
@jehiah jehiah mentioned this pull request May 8, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants