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

app engine support #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

app engine support #60

wants to merge 2 commits into from

Conversation

jtolio
Copy link

@jtolio jtolio commented Dec 29, 2016

App Engine requires use of context-specific HTTP clients. Outbound
HTTP requests simply don't work unless there's a way to provide
the current request context to the outgoing request.

Because a *Consumer might outlast multiple requests, we need a way
to thread the request context through and then optionally create
an *http.Client based on it. Unfortunately, this requires adding
a bunch of new arguments.

My preference would be to require contexts for all callsites, but
I realize that breaks backwards compatibility, so I've added new
methods.

App Engine requires use of context-specific HTTP clients. Outbound
HTTP requests simply don't work unless there's a way to provide
the current request context to the outgoing request.

Because a *Consumer might outlast multiple requests, we need a way
to thread the request context through and then optionally create
an *http.Client based on it. Unfortunately, this requires adding
a bunch of new arguments.

My preference would be to require contexts for all callsites, but
I realize that breaks backwards compatibility, so I've added new
methods.
jtolio added a commit to jtolio/goth that referenced this pull request Dec 29, 2016
App Engine unfortunately can't make outbound requests without using
the appengine urlfetch library and a request-specific context.

I don't see a way around this other than to change the signature of
the Provider and Session interfaces.

This really has a huge amount of downsides obviously, but before I
go and fix stuff for providers besides Facebook, G+, and Twitter
(Twitter support requires mrjones/oauth#60
to get merged), I figured I'd open a pull request and discuss the
tradeoffs.

Unfortunately I think we need to do something like this to support
App Engine. Perhaps this is an opportunity to version goth using
gopkg.in or something?
jtolio added a commit to jtolio/goth that referenced this pull request Dec 30, 2016
App Engine unfortunately can't make outbound requests without using
the appengine urlfetch library and a request-specific context.

I don't see a way around this other than to change the signature of
the Provider and Session interfaces.

This really has a huge amount of downsides obviously, but before I
go and fix stuff for providers besides Facebook, G+, and Twitter
(Twitter support requires mrjones/oauth#60
to get merged), I figured I'd open a pull request and discuss the
tradeoffs.

Unfortunately I think we need to do something like this to support
App Engine. Perhaps this is an opportunity to version goth using
gopkg.in or something?
@mrjones
Copy link
Owner

mrjones commented Jan 8, 2017

Hi, thanks for the patch. I'm really sorry it took me so long to get to it!

Admittedly, it's been quite some time since I've used AppEngine on a regular basis, so things could have changed. However, in the past it was possible to use this library inside of AppEngine by supplying your own HttpClient constructed using an AppEngine context.

Unfortunately, my original use case got migrated to OAuth 2.0, so I can't verify that it still works. However, I think this code is almost identical to the technique I used:

https://github.com/unrealities/warning-track/blob/cdfc6a1037339e27721f1171390ace4616a31b22/services/twitter.go

Eliding a few details it looks like:

// r is a *http.Request
c := appengine.NewContext(r)
client := urlfetch.Client(c)
consumer = oauth.NewCustomHttpClientConsumer(
tc.ConsumerKey,
tc.ConsumerSecret,
oauth.ServiceProvider{
RequestTokenUrl: = [...]
},
client);

Will this existing interface meet your needs?

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

Successfully merging this pull request may close these issues.

None yet

2 participants