summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/markbates/goth/providers/github/github.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/markbates/goth/providers/github/github.go')
-rw-r--r--vendor/github.com/markbates/goth/providers/github/github.go31
1 files changed, 20 insertions, 11 deletions
diff --git a/vendor/github.com/markbates/goth/providers/github/github.go b/vendor/github.com/markbates/goth/providers/github/github.go
index 866150e63a..b3c29b9670 100644
--- a/vendor/github.com/markbates/goth/providers/github/github.go
+++ b/vendor/github.com/markbates/goth/providers/github/github.go
@@ -37,13 +37,20 @@ var (
// You should always call `github.New` to get a new Provider. Never try to create
// one manually.
func New(clientKey, secret, callbackURL string, scopes ...string) *Provider {
+ return NewCustomisedURL(clientKey, secret, callbackURL, AuthURL, TokenURL, ProfileURL, EmailURL, scopes...)
+}
+
+// NewCustomisedURL is similar to New(...) but can be used to set custom URLs to connect to
+func NewCustomisedURL(clientKey, secret, callbackURL, authURL, tokenURL, profileURL, emailURL string, scopes ...string) *Provider {
p := &Provider{
- ClientKey: clientKey,
- Secret: secret,
- CallbackURL: callbackURL,
- providerName: "github",
- }
- p.config = newConfig(p, scopes)
+ ClientKey: clientKey,
+ Secret: secret,
+ CallbackURL: callbackURL,
+ providerName: "github",
+ profileURL: profileURL,
+ emailURL: emailURL,
+ }
+ p.config = newConfig(p, authURL, tokenURL, scopes)
return p
}
@@ -55,6 +62,8 @@ type Provider struct {
HTTPClient *http.Client
config *oauth2.Config
providerName string
+ profileURL string
+ emailURL string
}
// Name is the name used to retrieve this provider later.
@@ -96,7 +105,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s cannot get user information without accessToken", p.providerName)
}
- response, err := p.Client().Get(ProfileURL + "?access_token=" + url.QueryEscape(sess.AccessToken))
+ response, err := p.Client().Get(p.profileURL + "?access_token=" + url.QueryEscape(sess.AccessToken))
if err != nil {
return user, err
}
@@ -163,7 +172,7 @@ func userFromReader(reader io.Reader, user *goth.User) error {
}
func getPrivateMail(p *Provider, sess *Session) (email string, err error) {
- response, err := p.Client().Get(EmailURL + "?access_token=" + url.QueryEscape(sess.AccessToken))
+ response, err := p.Client().Get(p.emailURL + "?access_token=" + url.QueryEscape(sess.AccessToken))
if err != nil {
if response != nil {
response.Body.Close()
@@ -194,14 +203,14 @@ func getPrivateMail(p *Provider, sess *Session) (email string, err error) {
return
}
-func newConfig(provider *Provider, scopes []string) *oauth2.Config {
+func newConfig(provider *Provider, authURL, tokenURL string, scopes []string) *oauth2.Config {
c := &oauth2.Config{
ClientID: provider.ClientKey,
ClientSecret: provider.Secret,
RedirectURL: provider.CallbackURL,
Endpoint: oauth2.Endpoint{
- AuthURL: AuthURL,
- TokenURL: TokenURL,
+ AuthURL: authURL,
+ TokenURL: tokenURL,
},
Scopes: []string{},
}