mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	Additional OAuth2 providers (#1010)
* add google+ * sort signin oauth2 providers based on the name so order is always the same * update auth tip for google+ * add gitlab provider * add bitbucket provider (and some go fmt) * add twitter provider * add facebook provider * add dropbox provider * add openid connect provider incl. new format of tips section in "Add New Source" * lower the amount of disk storage for each session to prevent issues while building cross platform (and disk overflow) * imports according to goimport and code style * make it possible to set custom urls to gitlab and github provider (only these could have a different host) * split up oauth2 into multiple files * small typo in comment * fix indention * fix indentation * fix new line before external import * fix layout of signin part * update "broken" dependency
This commit is contained in:
		
				
					committed by
					
						 Lunny Xiao
						Lunny Xiao
					
				
			
			
				
	
			
			
			
						parent
						
							2368bbb672
						
					
				
				
					commit
					950f2e2074
				
			
							
								
								
									
										29
									
								
								vendor/github.com/markbates/goth/providers/github/github.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										29
									
								
								vendor/github.com/markbates/goth/providers/github/github.go
									
									
									
										generated
									
									
										vendored
									
									
								
							| @@ -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", | ||||
| 		ClientKey:    clientKey, | ||||
| 		Secret:       secret, | ||||
| 		CallbackURL:  callbackURL, | ||||
| 		providerName: "github", | ||||
| 		profileURL:   profileURL, | ||||
| 		emailURL:     emailURL, | ||||
| 	} | ||||
| 	p.config = newConfig(p, scopes) | ||||
| 	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{}, | ||||
| 	} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user