aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/markbates/goth/providers/facebook/facebook.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/markbates/goth/providers/facebook/facebook.go')
-rw-r--r--vendor/github.com/markbates/goth/providers/facebook/facebook.go42
1 files changed, 20 insertions, 22 deletions
diff --git a/vendor/github.com/markbates/goth/providers/facebook/facebook.go b/vendor/github.com/markbates/goth/providers/facebook/facebook.go
index 5c80ca747b..dd13580a34 100644
--- a/vendor/github.com/markbates/goth/providers/facebook/facebook.go
+++ b/vendor/github.com/markbates/goth/providers/facebook/facebook.go
@@ -37,6 +37,7 @@ func New(clientKey, secret, callbackURL string, scopes ...string) *Provider {
providerName: "facebook",
}
p.config = newConfig(p, scopes)
+ p.Fields = "email,first_name,last_name,link,about,id,name,picture,location"
return p
}
@@ -46,6 +47,7 @@ type Provider struct {
Secret string
CallbackURL string
HTTPClient *http.Client
+ Fields string
config *oauth2.Config
providerName string
}
@@ -60,6 +62,16 @@ func (p *Provider) SetName(name string) {
p.providerName = name
}
+// SetCustomFields sets the fields used to return information
+// for a user.
+//
+// A list of available field values can be found at
+// https://developers.facebook.com/docs/graph-api/reference/user
+func (p *Provider) SetCustomFields(fields []string) *Provider {
+ p.Fields = strings.Join(fields, ",")
+ return p
+}
+
func (p *Provider) Client() *http.Client {
return goth.HTTPClientWithFallBack(p.HTTPClient)
}
@@ -99,7 +111,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
reqUrl := fmt.Sprint(
endpointProfile,
- strings.Join(p.config.Scopes, ","),
+ p.Fields,
"&access_token=",
url.QueryEscape(sess.AccessToken),
"&appsecret_proof=",
@@ -177,31 +189,17 @@ func newConfig(provider *Provider, scopes []string) *oauth2.Config {
},
Scopes: []string{
"email",
- "first_name",
- "last_name",
- "link",
- "about",
- "id",
- "name",
- "picture",
- "location",
},
}
- // creates possibility to invoke field method like 'picture.type(large)'
- var found bool
- for _, sc := range scopes {
- sc := sc
- for i, defScope := range c.Scopes {
- if defScope == strings.Split(sc, ".")[0] {
- c.Scopes[i] = sc
- found = true
- }
- }
- if !found {
- c.Scopes = append(c.Scopes, sc)
+ defaultScopes := map[string]struct{}{
+ "email": {},
+ }
+
+ for _, scope := range scopes {
+ if _, exists := defaultScopes[scope]; !exists {
+ c.Scopes = append(c.Scopes, scope)
}
- found = false
}
return c