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

Support for Google AppEngine urlfetch for OAuth2 #23

Merged
merged 1 commit into from Nov 13, 2014

Conversation

jonathana
Copy link
Contributor

To use http in Google AppEngine, you have to use urlfetch, not
the normal default http client or RoundTripper. So similar to
what one of the forks of goauth2 did, this adds the ability via
the now-added common/SetRoundTripper to pass in the specific
RoundTripper to use. If unset, the default net/http one will be
used. However, by calling this method, you can pass in your own
including one created via urlfetch. Here is sample code showing
it in use:

import (
"appengine"
"github.com/stretchr/gomniauth/common"
)

func SomeGolangFunc([...,] r *http.Request [,...]) {
c := appengine.NewContext(r)
t := new(urlfetch.Transport)
t.Context = c
common.SetRoundTripper(t)

// Do something interesting here
}

Note that common.SetRoundTripper may have to be called in the GAE
server before every request, versus trying to do it once because
of the appengine.Context being passed in. Pretty sure you cannot
pass in a nil *http.Request and re-use the context, so you can't
make the call during the GAE init() method.

To use http in Google AppEngine, you have to use urlfetch, not
the normal default http client or RoundTripper.  So similar to
what one of the forks of goauth2 did, this adds the ability via
the now-added common/SetRoundTripper to pass in the specific
RoundTripper to use.  If unset, the default net/http one will be
used.  However, by calling this method, you can pass in your own
including one created via urlfetch.  Here is sample code showing
it in use:

import (
  "appengine"
  "github.com/stretchr/gomniauth/common"
)

func SomeGolangFunc([...,] r *http.Request [,...]) {
  c := appengine.NewContext(r)
  t := new(urlfetch.Transport)
  t.Context = c
  common.SetRoundTripper(t)

  // Do something interesting here
}

Note that common.SetRoundTripper may have to be called in the GAE
server before every request, versus trying to do it once because
of the appengine.Context being passed in.  Pretty sure you cannot
pass in a nil *http.Request and re-use the context, so you can't
make the call during the GAE init() method.
matryer pushed a commit that referenced this pull request Nov 13, 2014
Support for Google AppEngine urlfetch for OAuth2
@matryer matryer merged commit d113c64 into stretchr:master Nov 13, 2014
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