Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GAE compatibility (urlfetch) #27

Closed
RubenN opened this issue Feb 16, 2015 · 8 comments
Closed

GAE compatibility (urlfetch) #27

RubenN opened this issue Feb 16, 2015 · 8 comments

Comments

@RubenN
Copy link

RubenN commented Feb 16, 2015

I'd like to use this on app engine.
What would the best way be to get the proper (urlfetch) compatible Transport in?
(FetchUser uses the default http.Get)

The result i got was:

Post https://accounts.google.com/o/oauth2/token: http.DefaultTransport and http.DefaultClient are not available in App Engine. See https://cloud.google.com/appengine/docs/go/urlfetch/

@tylerstillwater
Copy link
Collaborator

The pattern for this kind of thing thus far has been callback functions that the user can set to provide customized functionality.

I would recommend having an GetClient() function that returns the http.Client to use for fetching the URL. By default, this should return a new client, but it could be overridden by calling code (see GetProviderName) to return the urlfetch.Client for use on App Engine.

This also has the added benefit of not strongly binding goth to any app engine code or logic.

@markbates thoughts?

@RubenN
Copy link
Author

RubenN commented Feb 18, 2015

Sounds like a valid solution if it is in line with Mark's thoughts.

@markbates
Copy link
Owner

I don't use GAE, so I'm not sure of the exact nature of the problem, so I'll leave this to Tyler's discretion, as he seems to have a handle on this.

@tylerstillwater
Copy link
Collaborator

Sounds good. The approach I posted above should work just fine. @RubenN do you want to go ahead and implement this, then submit a PR?

@RubenN
Copy link
Author

RubenN commented Feb 19, 2015

Ok

@RubenN
Copy link
Author

RubenN commented Feb 19, 2015

It turned out to be even simpler and doesn't require code changes.
The key is to change the default http client and transport like this:

http.DefaultClient = &http.Client{ Transport: &urlfetch.Transport{Context: c}, } http.DefaultTransport = &urlfetch.Transport{Context: c}

@RubenN RubenN closed this as completed Feb 19, 2015
@oyvindsk
Copy link

oyvindsk commented Oct 7, 2015

For the record, this does not work anymore with newer versions of oauth2. It looks like it should be unnecessary now, but I can't get it to work at all with oauth2 released after this commit:
golang/oauth2@96e89be

Works if you revert back to before that commit and use @RubenN 's sollution

@markbates
Copy link
Owner

As before, I don't use GAE, so I can't produce. However, @oyvindsk if you can reproduce and know a fix please submit a PR so we can close this. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants