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

proposal: app engine support #113

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 15 additions & 0 deletions client.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// +build !appengine

package goth

import (
"net/http"

"golang.org/x/net/context"
)

// Provider implementations should use this method for making outbound HTTP
// requests.
var HTTPClient = func(ctx context.Context) (*http.Client, error) {
return http.DefaultClient, nil
}
16 changes: 16 additions & 0 deletions client_appengine.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// +build appengine

package goth

import (
"net/http"

"golang.org/x/net/context"
"google.golang.org/appengine/urlfetch"
)

// Provider implementations should use this method for making outbound HTTP
// requests.
var HTTPClient = func(ctx context.Context) (*http.Client, error) {
return urlfetch.Client(ctx), nil
}
68 changes: 34 additions & 34 deletions examples/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,40 +10,40 @@ import (

"github.com/gorilla/pat"
"github.com/gorilla/sessions"
"github.com/markbates/goth"
"github.com/markbates/goth/gothic"
"github.com/markbates/goth/providers/amazon"
"github.com/markbates/goth/providers/bitbucket"
"github.com/markbates/goth/providers/box"
"github.com/markbates/goth/providers/dailymotion"
"github.com/markbates/goth/providers/deezer"
"github.com/markbates/goth/providers/digitalocean"
"github.com/markbates/goth/providers/discord"
"github.com/markbates/goth/providers/dropbox"
"github.com/markbates/goth/providers/facebook"
"github.com/markbates/goth/providers/fitbit"
"github.com/markbates/goth/providers/github"
"github.com/markbates/goth/providers/gitlab"
"github.com/markbates/goth/providers/gplus"
"github.com/markbates/goth/providers/heroku"
"github.com/markbates/goth/providers/instagram"
"github.com/markbates/goth/providers/intercom"
"github.com/markbates/goth/providers/lastfm"
"github.com/markbates/goth/providers/linkedin"
"github.com/markbates/goth/providers/onedrive"
"github.com/markbates/goth/providers/paypal"
"github.com/markbates/goth/providers/salesforce"
"github.com/markbates/goth/providers/slack"
"github.com/markbates/goth/providers/soundcloud"
"github.com/markbates/goth/providers/spotify"
"github.com/markbates/goth/providers/steam"
"github.com/markbates/goth/providers/stripe"
"github.com/markbates/goth/providers/twitch"
"github.com/markbates/goth/providers/twitter"
"github.com/markbates/goth/providers/uber"
"github.com/markbates/goth/providers/wepay"
"github.com/markbates/goth/providers/yahoo"
"github.com/markbates/goth/providers/yammer"
"github.com/jtolds/goth"
"github.com/jtolds/goth/gothic"
"github.com/jtolds/goth/providers/amazon"
"github.com/jtolds/goth/providers/bitbucket"
"github.com/jtolds/goth/providers/box"
"github.com/jtolds/goth/providers/dailymotion"
"github.com/jtolds/goth/providers/deezer"
"github.com/jtolds/goth/providers/digitalocean"
"github.com/jtolds/goth/providers/discord"
"github.com/jtolds/goth/providers/dropbox"
"github.com/jtolds/goth/providers/facebook"
"github.com/jtolds/goth/providers/fitbit"
"github.com/jtolds/goth/providers/github"
"github.com/jtolds/goth/providers/gitlab"
"github.com/jtolds/goth/providers/gplus"
"github.com/jtolds/goth/providers/heroku"
"github.com/jtolds/goth/providers/instagram"
"github.com/jtolds/goth/providers/intercom"
"github.com/jtolds/goth/providers/lastfm"
"github.com/jtolds/goth/providers/linkedin"
"github.com/jtolds/goth/providers/onedrive"
"github.com/jtolds/goth/providers/paypal"
"github.com/jtolds/goth/providers/salesforce"
"github.com/jtolds/goth/providers/slack"
"github.com/jtolds/goth/providers/soundcloud"
"github.com/jtolds/goth/providers/spotify"
"github.com/jtolds/goth/providers/steam"
"github.com/jtolds/goth/providers/stripe"
"github.com/jtolds/goth/providers/twitch"
"github.com/jtolds/goth/providers/twitter"
"github.com/jtolds/goth/providers/uber"
"github.com/jtolds/goth/providers/wepay"
"github.com/jtolds/goth/providers/yahoo"
"github.com/jtolds/goth/providers/yammer"
)

func init() {
Expand Down
8 changes: 4 additions & 4 deletions gothic/gothic.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Package gothic wraps common behaviour when using Goth. This makes it quick, and
and running with Goth. Of course, if you want complete control over how things flow, in regards
to the authentication process, feel free and use Goth directly.

See https://github.com/markbates/goth/examples/main.go to see this in action.
See https://github.com/jtolds/goth/examples/main.go to see this in action.
*/
package gothic

Expand All @@ -15,7 +15,7 @@ import (

"github.com/gorilla/mux"
"github.com/gorilla/sessions"
"github.com/markbates/goth"
"github.com/jtolds/goth"
)

// SessionName is the key used to access the session store.
Expand All @@ -42,7 +42,7 @@ as either "provider" or ":provider".
BeginAuthHandler will redirect the user to the appropriate authentication end-point
for the requested provider.

See https://github.com/markbates/goth/examples/main.go to see this in action.
See https://github.com/jtolds/goth/examples/main.go to see this in action.
*/
func BeginAuthHandler(res http.ResponseWriter, req *http.Request) {
url, err := GetAuthURL(res, req)
Expand Down Expand Up @@ -128,7 +128,7 @@ process and fetches all of the basic information about the user from the provide
It expects to be able to get the name of the provider from the query parameters
as either "provider" or ":provider".

See https://github.com/markbates/goth/examples/main.go to see this in action.
See https://github.com/jtolds/goth/examples/main.go to see this in action.
*/
var CompleteUserAuth = func(res http.ResponseWriter, req *http.Request) (goth.User, error) {

Expand Down
6 changes: 3 additions & 3 deletions gothic/gothic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import (
"testing"

"github.com/gorilla/sessions"
"github.com/markbates/goth"
. "github.com/markbates/goth/gothic"
"github.com/markbates/goth/providers/faux"
"github.com/jtolds/goth"
. "github.com/jtolds/goth/gothic"
"github.com/jtolds/goth/providers/faux"
"github.com/stretchr/testify/assert"
)

Expand Down
28 changes: 22 additions & 6 deletions provider.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
package goth

import "fmt"
import "golang.org/x/oauth2"
import (
"fmt"

"golang.org/x/net/context"
"golang.org/x/oauth2"
)

// Provider needs to be implemented for each 3rd party authentication provider
// e.g. Facebook, Twitter, etc...
type Provider interface {
// When implementing a provider, these methods should not make outbound
// requests.
Name() string
BeginAuth(state string) (Session, error)
UnmarshalSession(string) (Session, error)
FetchUser(Session) (User, error)
Debug(bool)
RefreshToken(refreshToken string) (*oauth2.Token, error) //Get new access token based on the refresh token
RefreshTokenAvailable() bool //Refresh token is provided by auth provider or not
// Refresh token is provided by auth provider or not
RefreshTokenAvailable() bool

// These three methods are deprecated. See the appropriate *Ctx replacement.
BeginAuth(state string) (Session, error)
FetchUser(Session) (User, error)
RefreshToken(refreshToken string) (*oauth2.Token, error)

// These methods are now preferred.
BeginAuthCtx(ctx context.Context, state string) (Session, error)
FetchUserCtx(context.Context, Session) (User, error)
// Get new access token based on the refresh token.
// Only works if RefreshTokenAvailable() is true
RefreshTokenCtx(ctx context.Context, refreshToken string) (*oauth2.Token, error)
}

// Providers is list of known/available providers.
Expand Down
4 changes: 2 additions & 2 deletions provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package goth_test
import (
"testing"

"github.com/markbates/goth"
"github.com/markbates/goth/providers/faux"
"github.com/jtolds/goth"
"github.com/jtolds/goth/providers/faux"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion providers/amazon/amazon.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ package amazon
import (
"bytes"
"encoding/json"
"github.com/markbates/goth"
"github.com/jtolds/goth"
"golang.org/x/oauth2"
"io"
"io/ioutil"
Expand Down
4 changes: 2 additions & 2 deletions providers/amazon/amazon_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package amazon_test

import (
"github.com/markbates/goth"
"github.com/markbates/goth/providers/amazon"
"github.com/jtolds/goth"
"github.com/jtolds/goth/providers/amazon"
"github.com/stretchr/testify/assert"
"os"
"testing"
Expand Down
2 changes: 1 addition & 1 deletion providers/amazon/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package amazon
import (
"encoding/json"
"errors"
"github.com/markbates/goth"
"github.com/jtolds/goth"
"golang.org/x/oauth2"
"strings"
"time"
Expand Down
4 changes: 2 additions & 2 deletions providers/amazon/session_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package amazon_test

import (
"github.com/markbates/goth"
"github.com/markbates/goth/providers/amazon"
"github.com/jtolds/goth"
"github.com/jtolds/goth/providers/amazon"
"github.com/stretchr/testify/assert"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion providers/bitbucket/bitbucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package bitbucket
import (
"bytes"
"encoding/json"
"github.com/markbates/goth"
"github.com/jtolds/goth"
"golang.org/x/oauth2"
"io"
"io/ioutil"
Expand Down
4 changes: 2 additions & 2 deletions providers/bitbucket/bitbucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"os"
"testing"

"github.com/markbates/goth"
"github.com/markbates/goth/providers/bitbucket"
"github.com/jtolds/goth"
"github.com/jtolds/goth/providers/bitbucket"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion providers/bitbucket/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package bitbucket
import (
"encoding/json"
"errors"
"github.com/markbates/goth"
"github.com/jtolds/goth"
"golang.org/x/oauth2"
"strings"
"time"
Expand Down
4 changes: 2 additions & 2 deletions providers/bitbucket/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package bitbucket_test
import (
"testing"

"github.com/markbates/goth"
"github.com/markbates/goth/providers/bitbucket"
"github.com/jtolds/goth"
"github.com/jtolds/goth/providers/bitbucket"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion providers/box/box.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package box

import (
"encoding/json"
"github.com/markbates/goth"
"github.com/jtolds/goth"
"golang.org/x/oauth2"
"io"
"net/http"
Expand Down
4 changes: 2 additions & 2 deletions providers/box/box_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package box_test

import (
"github.com/markbates/goth"
"github.com/markbates/goth/providers/box"
"github.com/jtolds/goth"
"github.com/jtolds/goth/providers/box"
"github.com/stretchr/testify/assert"
"os"
"testing"
Expand Down
2 changes: 1 addition & 1 deletion providers/box/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package box
import (
"encoding/json"
"errors"
"github.com/markbates/goth"
"github.com/jtolds/goth"
"golang.org/x/oauth2"
"strings"
"time"
Expand Down
4 changes: 2 additions & 2 deletions providers/box/session_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package box_test

import (
"github.com/markbates/goth"
"github.com/markbates/goth/providers/box"
"github.com/jtolds/goth"
"github.com/jtolds/goth/providers/box"
"github.com/stretchr/testify/assert"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion providers/cloudfoundry/cf.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"
"strings"

"github.com/markbates/goth"
"github.com/jtolds/goth"
"golang.org/x/net/context"
"golang.org/x/oauth2"
)
Expand Down
4 changes: 2 additions & 2 deletions providers/cloudfoundry/cf_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cloudfoundry_test

import (
"github.com/markbates/goth"
"github.com/markbates/goth/providers/cloudfoundry"
"github.com/jtolds/goth"
"github.com/jtolds/goth/providers/cloudfoundry"
"github.com/stretchr/testify/assert"
"os"
"testing"
Expand Down
2 changes: 1 addition & 1 deletion providers/cloudfoundry/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"time"

"github.com/markbates/goth"
"github.com/jtolds/goth"
"golang.org/x/net/context"
"golang.org/x/oauth2"
)
Expand Down
4 changes: 2 additions & 2 deletions providers/cloudfoundry/session_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package cloudfoundry_test

import (
"github.com/markbates/goth"
"github.com/markbates/goth/providers/cloudfoundry"
"github.com/jtolds/goth"
"github.com/jtolds/goth/providers/cloudfoundry"
"github.com/stretchr/testify/assert"
"testing"
)
Expand Down
2 changes: 1 addition & 1 deletion providers/dailymotion/dailymotion.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"net/http"
"net/url"

"github.com/markbates/goth"
"github.com/jtolds/goth"
"golang.org/x/oauth2"
)

Expand Down
4 changes: 2 additions & 2 deletions providers/dailymotion/dailymotion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"os"
"testing"

"github.com/markbates/goth"
"github.com/markbates/goth/providers/dailymotion"
"github.com/jtolds/goth"
"github.com/jtolds/goth/providers/dailymotion"
"github.com/stretchr/testify/assert"
)

Expand Down
2 changes: 1 addition & 1 deletion providers/dailymotion/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package dailymotion
import (
"encoding/json"
"errors"
"github.com/markbates/goth"
"github.com/jtolds/goth"
"golang.org/x/oauth2"
"strings"
"time"
Expand Down