mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-28 08:07:48 -04:00 
			
		
		
		
	Update markbates/goth libary to fix OAuth2 support (#3661)
This commit is contained in:
		
							
								
								
									
										15
									
								
								vendor/github.com/markbates/goth/gothic/gothic.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										15
									
								
								vendor/github.com/markbates/goth/gothic/gothic.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -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 { | ||||
|   | ||||
							
								
								
									
										45
									
								
								vendor/github.com/markbates/goth/providers/dropbox/dropbox.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										45
									
								
								vendor/github.com/markbates/goth/providers/dropbox/dropbox.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -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 | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user