summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/markbates
diff options
context:
space:
mode:
authorLauris BH <lauris@nix.lv>2018-03-13 01:35:46 +0200
committerGitHub <noreply@github.com>2018-03-13 01:35:46 +0200
commitad33730dcaffed632200316a5ce5675b30ed1e99 (patch)
tree4124e40576159ad7e093b786c309321f3b13fa16 /vendor/github.com/markbates
parent575c109a02b04ff449fad31e1ba595869842bd9a (diff)
downloadgitea-ad33730dcaffed632200316a5ce5675b30ed1e99.tar.gz
gitea-ad33730dcaffed632200316a5ce5675b30ed1e99.zip
Update markbates/goth libary to fix OAuth2 support (#3661)
Diffstat (limited to 'vendor/github.com/markbates')
-rw-r--r--vendor/github.com/markbates/goth/gothic/gothic.go15
-rw-r--r--vendor/github.com/markbates/goth/providers/dropbox/dropbox.go45
2 files changed, 42 insertions, 18 deletions
diff --git a/vendor/github.com/markbates/goth/gothic/gothic.go b/vendor/github.com/markbates/goth/gothic/gothic.go
index 8b8e114940..7d6ac2ab6a 100644
--- a/vendor/github.com/markbates/goth/gothic/gothic.go
+++ b/vendor/github.com/markbates/goth/gothic/gothic.go
@@ -132,7 +132,7 @@ func GetAuthURL(res http.ResponseWriter, req *http.Request) (string, error) {
return "", err
}
- err = storeInSession(providerName, sess.Marshal(), req, res)
+ err = StoreInSession(providerName, sess.Marshal(), req, res)
if err != nil {
return "", err
@@ -166,7 +166,7 @@ var CompleteUserAuth = func(res http.ResponseWriter, req *http.Request) (goth.Us
return goth.User{}, err
}
- value, err := getFromSession(providerName, req)
+ value, err := GetFromSession(providerName, req)
if err != nil {
return goth.User{}, err
}
@@ -193,7 +193,7 @@ var CompleteUserAuth = func(res http.ResponseWriter, req *http.Request) (goth.Us
return goth.User{}, err
}
- err = storeInSession(providerName, sess.Marshal(), req, res)
+ err = StoreInSession(providerName, sess.Marshal(), req, res)
if err != nil {
return goth.User{}, err
@@ -284,8 +284,9 @@ func getProviderName(req *http.Request) (string, error) {
return "", errors.New("you must select a provider")
}
-func storeInSession(key string, value string, req *http.Request, res http.ResponseWriter) error {
- session, _ := Store.Get(req, SessionName)
+// StoreInSession stores a specified key/value pair in the session.
+func StoreInSession(key string, value string, req *http.Request, res http.ResponseWriter) error {
+ session, _ := Store.New(req, SessionName)
if err := updateSessionValue(session, key, value); err != nil {
return err
@@ -294,7 +295,9 @@ func storeInSession(key string, value string, req *http.Request, res http.Respon
return session.Save(req, res)
}
-func getFromSession(key string, req *http.Request) (string, error) {
+// GetFromSession retrieves a previously-stored value from the session.
+// If no value has previously been stored at the specified key, it will return an error.
+func GetFromSession(key string, req *http.Request) (string, error) {
session, _ := Store.Get(req, SessionName)
value, err := getSessionValue(session, key)
if err != nil {
diff --git a/vendor/github.com/markbates/goth/providers/dropbox/dropbox.go b/vendor/github.com/markbates/goth/providers/dropbox/dropbox.go
index 262905806b..6133626f21 100644
--- a/vendor/github.com/markbates/goth/providers/dropbox/dropbox.go
+++ b/vendor/github.com/markbates/goth/providers/dropbox/dropbox.go
@@ -2,9 +2,11 @@
package dropbox
import (
+ "bytes"
"encoding/json"
"errors"
"io"
+ "io/ioutil"
"net/http"
"strings"
@@ -25,6 +27,7 @@ type Provider struct {
ClientKey string
Secret string
CallbackURL string
+ AccountURL string
HTTPClient *http.Client
config *oauth2.Config
providerName string
@@ -44,6 +47,7 @@ func New(clientKey, secret, callbackURL string, scopes ...string) *Provider {
ClientKey: clientKey,
Secret: secret,
CallbackURL: callbackURL,
+ AccountURL: accountURL,
providerName: "dropbox",
}
p.config = newConfig(p, scopes)
@@ -87,7 +91,7 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s cannot get user information without accessToken", p.providerName)
}
- req, err := http.NewRequest("POST", accountURL, nil)
+ req, err := http.NewRequest("POST", p.AccountURL, nil)
if err != nil {
return user, err
}
@@ -102,7 +106,17 @@ func (p *Provider) FetchUser(session goth.Session) (goth.User, error) {
return user, fmt.Errorf("%s responded with a %d trying to fetch user information", p.providerName, resp.StatusCode)
}
- err = userFromReader(resp.Body, &user)
+ bits, err := ioutil.ReadAll(resp.Body)
+ if err != nil {
+ return user, err
+ }
+
+ err = json.NewDecoder(bytes.NewReader(bits)).Decode(&user.RawData)
+ if err != nil {
+ return user, err
+ }
+
+ err = userFromReader(bytes.NewReader(bits), &user)
return user, err
}
@@ -162,22 +176,29 @@ func newConfig(p *Provider, scopes []string) *oauth2.Config {
func userFromReader(r io.Reader, user *goth.User) error {
u := struct {
- Name string `json:"display_name"`
- NameDetails struct {
- NickName string `json:"familiar_name"`
- } `json:"name_details"`
- Location string `json:"country"`
- Email string `json:"email"`
+ AccountID string `json:"account_id"`
+ Name struct {
+ GivenName string `json:"given_name"`
+ Surname string `json:"surname"`
+ DisplayName string `json:"display_name"`
+ } `json:"name"`
+ Country string `json:"country"`
+ Email string `json:"email"`
+ ProfilePhotoURL string `json:"profile_photo_url"`
}{}
err := json.NewDecoder(r).Decode(&u)
if err != nil {
return err
}
+ user.UserID = u.AccountID // The user's unique Dropbox ID.
+ user.FirstName = u.Name.GivenName
+ user.LastName = u.Name.Surname
+ user.Name = strings.TrimSpace(fmt.Sprintf("%s %s", u.Name.GivenName, u.Name.Surname))
+ user.Description = u.Name.DisplayName // Full name plus parenthetical team naem
user.Email = u.Email
- user.Name = u.Name
- user.NickName = u.NameDetails.NickName
- user.UserID = u.Email // Dropbox doesn't provide a separate user ID
- user.Location = u.Location
+ user.NickName = u.Email // Email is the dropbox username
+ user.Location = u.Country
+ user.AvatarURL = u.ProfilePhotoURL // May be blank
return nil
}