mirror of
				https://gitee.com/gitea/gitea
				synced 2025-11-04 16:40:24 +08:00 
			
		
		
		
	Fix issue with log in with GitHub but need more error handle after
This commit is contained in:
		@@ -79,6 +79,7 @@ ENABLED = false
 | 
				
			|||||||
ENABLED =
 | 
					ENABLED =
 | 
				
			||||||
CLIENT_ID = 
 | 
					CLIENT_ID = 
 | 
				
			||||||
CLIENT_SECRET = 
 | 
					CLIENT_SECRET = 
 | 
				
			||||||
 | 
					SCOPES = https://api.github.com/user
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[cache]
 | 
					[cache]
 | 
				
			||||||
; Either "memory", "redis", or "memcache", default is "memory"
 | 
					; Either "memory", "redis", or "memcache", default is "memory"
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -34,6 +34,7 @@ type Oauther struct {
 | 
				
			|||||||
	GitHub struct {
 | 
						GitHub struct {
 | 
				
			||||||
		Enabled                bool
 | 
							Enabled                bool
 | 
				
			||||||
		ClientId, ClientSecret string
 | 
							ClientId, ClientSecret string
 | 
				
			||||||
 | 
							Scopes                 string
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -263,6 +264,7 @@ func newOauthService() {
 | 
				
			|||||||
		OauthService.GitHub.Enabled = true
 | 
							OauthService.GitHub.Enabled = true
 | 
				
			||||||
		OauthService.GitHub.ClientId = Cfg.MustValue("oauth.github", "CLIENT_ID")
 | 
							OauthService.GitHub.ClientId = Cfg.MustValue("oauth.github", "CLIENT_ID")
 | 
				
			||||||
		OauthService.GitHub.ClientSecret = Cfg.MustValue("oauth.github", "CLIENT_SECRET")
 | 
							OauthService.GitHub.ClientSecret = Cfg.MustValue("oauth.github", "CLIENT_SECRET")
 | 
				
			||||||
 | 
							OauthService.GitHub.Scopes = Cfg.MustValue("oauth.github", "SCOPES")
 | 
				
			||||||
		oauths = append(oauths, "GitHub")
 | 
							oauths = append(oauths, "GitHub")
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										24
									
								
								web.go
									
									
									
									
									
								
							
							
						
						
									
										24
									
								
								web.go
									
									
									
									
									
								
							@@ -59,20 +59,16 @@ func runWeb(*cli.Context) {
 | 
				
			|||||||
	m.Use(middleware.Renderer(middleware.RenderOptions{Funcs: []template.FuncMap{base.TemplateFuncs}}))
 | 
						m.Use(middleware.Renderer(middleware.RenderOptions{Funcs: []template.FuncMap{base.TemplateFuncs}}))
 | 
				
			||||||
	m.Use(middleware.InitContext())
 | 
						m.Use(middleware.InitContext())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	scope := "https://api.github.com/user"
 | 
						if base.OauthService != nil {
 | 
				
			||||||
	// m.Use(sessions.Sessions("my_session", sessions.NewCookieStore([]byte("secret123"))))
 | 
							if base.OauthService.GitHub.Enabled {
 | 
				
			||||||
	// m.Use(oauth2.Github(&oauth2.Options{
 | 
								m.Use(oauth2.Github(&oauth2.Options{
 | 
				
			||||||
	// 	ClientId:     "09383403ff2dc16daaa1",
 | 
									ClientId:     base.OauthService.GitHub.ClientId,
 | 
				
			||||||
	// 	ClientSecret: "5f6e7101d30b77952aab22b75eadae17551ea6b5",
 | 
									ClientSecret: base.OauthService.GitHub.ClientSecret,
 | 
				
			||||||
	// 	RedirectURL:  base.AppUrl + oauth2.PathCallback,
 | 
									RedirectURL:  base.AppUrl + oauth2.PathCallback[1:],
 | 
				
			||||||
	// 	Scopes:       []string{scope},
 | 
									Scopes:       []string{base.OauthService.GitHub.Scopes},
 | 
				
			||||||
	// }))
 | 
								}))
 | 
				
			||||||
	m.Use(oauth2.Github(&oauth2.Options{
 | 
							}
 | 
				
			||||||
		ClientId:     "ba323b44192e65c7c320",
 | 
						}
 | 
				
			||||||
		ClientSecret: "6818ffed53bea5815bf1a6412d1933f25fa10619",
 | 
					 | 
				
			||||||
		RedirectURL:  base.AppUrl + oauth2.PathCallback[1:],
 | 
					 | 
				
			||||||
		Scopes:       []string{scope},
 | 
					 | 
				
			||||||
	}))
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	reqSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true})
 | 
						reqSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: true})
 | 
				
			||||||
	ignSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: base.Service.RequireSignInView})
 | 
						ignSignIn := middleware.Toggle(&middleware.ToggleOptions{SignInRequire: base.Service.RequireSignInView})
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user