1
1
mirror of https://github.com/go-gitea/gitea synced 2024-12-22 16:44:26 +00:00

Update markbates/goth libary to fix OAuth2 support (#3661)

This commit is contained in:
Lauris BH 2018-03-13 01:35:46 +02:00 committed by GitHub
parent 575c109a02
commit ad33730dca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 74 additions and 40 deletions

View File

@ -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 {

View File

@ -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
}

54
vendor/vendor.json vendored
View File

@ -667,63 +667,73 @@
},
{
"checksumSHA1": "q9MD1ienC+kmKq5i51oAktQEV1E=",
"origin": "github.com/go-gitea/goth",
"path": "github.com/markbates/goth",
"revision": "bc7deaf077a50416cf3a23aa5903d2a7b5a30ada",
"revisionTime": "2018-02-15T02:27:40Z"
"revision": "3b54d96084a5e11030f19556cf68a6ab5d93ba20",
"revisionTime": "2018-03-12T06:32:04Z"
},
{
"checksumSHA1": "+nosptSgGb2qCAR6CSHV2avwmNg=",
"checksumSHA1": "FISfgOkoMtn98wglLUvfBTZ6baE=",
"origin": "github.com/go-gitea/goth/gothic",
"path": "github.com/markbates/goth/gothic",
"revision": "bc7deaf077a50416cf3a23aa5903d2a7b5a30ada",
"revisionTime": "2018-02-15T02:27:40Z"
"revision": "3b54d96084a5e11030f19556cf68a6ab5d93ba20",
"revisionTime": "2018-03-12T06:32:04Z"
},
{
"checksumSHA1": "pJ+Cws/TU22K6tZ/ALFOvvH1K5U=",
"origin": "github.com/go-gitea/goth/providers/bitbucket",
"path": "github.com/markbates/goth/providers/bitbucket",
"revision": "bc7deaf077a50416cf3a23aa5903d2a7b5a30ada",
"revisionTime": "2018-02-15T02:27:40Z"
"revision": "3b54d96084a5e11030f19556cf68a6ab5d93ba20",
"revisionTime": "2018-03-12T06:32:04Z"
},
{
"checksumSHA1": "bKokLof0Pkk5nEhW8NdbfcVzuqk=",
"checksumSHA1": "XsF5HI4240QHbFXbtWWnGgTsoq8=",
"origin": "github.com/go-gitea/goth/providers/dropbox",
"path": "github.com/markbates/goth/providers/dropbox",
"revision": "bc7deaf077a50416cf3a23aa5903d2a7b5a30ada",
"revisionTime": "2018-02-15T02:27:40Z"
"revision": "3b54d96084a5e11030f19556cf68a6ab5d93ba20",
"revisionTime": "2018-03-12T06:32:04Z"
},
{
"checksumSHA1": "VzbroIA9R00Ig3iGnOlZLU7d4ls=",
"origin": "github.com/go-gitea/goth/providers/facebook",
"path": "github.com/markbates/goth/providers/facebook",
"revision": "bc7deaf077a50416cf3a23aa5903d2a7b5a30ada",
"revisionTime": "2018-02-15T02:27:40Z"
"revision": "3b54d96084a5e11030f19556cf68a6ab5d93ba20",
"revisionTime": "2018-03-12T06:32:04Z"
},
{
"checksumSHA1": "P6nBZ850aaekpOcoXNdRhK86bH8=",
"origin": "github.com/go-gitea/goth/providers/github",
"path": "github.com/markbates/goth/providers/github",
"revision": "bc7deaf077a50416cf3a23aa5903d2a7b5a30ada",
"revisionTime": "2018-02-15T02:27:40Z"
"revision": "3b54d96084a5e11030f19556cf68a6ab5d93ba20",
"revisionTime": "2018-03-12T06:32:04Z"
},
{
"checksumSHA1": "ld488t+yGoTwtmiCSSggEX4fxVk=",
"origin": "github.com/go-gitea/goth/providers/gitlab",
"path": "github.com/markbates/goth/providers/gitlab",
"revision": "bc7deaf077a50416cf3a23aa5903d2a7b5a30ada",
"revisionTime": "2018-02-15T02:27:40Z"
"revision": "3b54d96084a5e11030f19556cf68a6ab5d93ba20",
"revisionTime": "2018-03-12T06:32:04Z"
},
{
"checksumSHA1": "qXEulD7vnwY9hFrxh91Pm5YrvTM=",
"origin": "github.com/go-gitea/goth/providers/gplus",
"path": "github.com/markbates/goth/providers/gplus",
"revision": "bc7deaf077a50416cf3a23aa5903d2a7b5a30ada",
"revisionTime": "2018-02-15T02:27:40Z"
"revision": "3b54d96084a5e11030f19556cf68a6ab5d93ba20",
"revisionTime": "2018-03-12T06:32:04Z"
},
{
"checksumSHA1": "wsOBzyp4LKDhfCPmX1LLP7T0S3U=",
"origin": "github.com/go-gitea/goth/providers/openidConnect",
"path": "github.com/markbates/goth/providers/openidConnect",
"revision": "bc7deaf077a50416cf3a23aa5903d2a7b5a30ada",
"revisionTime": "2018-02-15T02:27:40Z"
"revision": "3b54d96084a5e11030f19556cf68a6ab5d93ba20",
"revisionTime": "2018-03-12T06:32:04Z"
},
{
"checksumSHA1": "o6RqMbbE8QNZhNT9TsAIRMPI8tg=",
"origin": "github.com/go-gitea/goth/providers/twitter",
"path": "github.com/markbates/goth/providers/twitter",
"revision": "bc7deaf077a50416cf3a23aa5903d2a7b5a30ada",
"revisionTime": "2018-02-15T02:27:40Z"
"revision": "3b54d96084a5e11030f19556cf68a6ab5d93ba20",
"revisionTime": "2018-03-12T06:32:04Z"
},
{
"checksumSHA1": "61HNjGetaBoMp8HBOpuEZRSim8g=",