|
@@ -41,7 +41,7 @@ func initGithub(redirectURL string, clientID string, clientSecret string) {
|
|
}
|
|
}
|
|
|
|
|
|
func handleGithubLogin(w http.ResponseWriter, r *http.Request) {
|
|
func handleGithubLogin(w http.ResponseWriter, r *http.Request) {
|
|
- oauth_state_string = logic.RandomString(16)
|
|
|
|
|
|
+ var oauth_state_string = logic.RandomString(16)
|
|
if auth_provider == nil && servercfg.GetFrontendURL() != "" {
|
|
if auth_provider == nil && servercfg.GetFrontendURL() != "" {
|
|
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
|
http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
|
return
|
|
return
|
|
@@ -49,6 +49,12 @@ func handleGithubLogin(w http.ResponseWriter, r *http.Request) {
|
|
fmt.Fprintf(w, "%s", []byte("no frontend URL was provided and an OAuth login was attempted\nplease reconfigure server to use OAuth or use basic credentials"))
|
|
fmt.Fprintf(w, "%s", []byte("no frontend URL was provided and an OAuth login was attempted\nplease reconfigure server to use OAuth or use basic credentials"))
|
|
return
|
|
return
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if err := logic.SetState(oauth_state_string); err != nil {
|
|
|
|
+ http.Redirect(w, r, servercfg.GetFrontendURL()+"/login?oauth=callback-error", http.StatusTemporaryRedirect)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
var url = auth_provider.AuthCodeURL(oauth_state_string)
|
|
var url = auth_provider.AuthCodeURL(oauth_state_string)
|
|
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
|
http.Redirect(w, r, url, http.StatusTemporaryRedirect)
|
|
}
|
|
}
|
|
@@ -88,7 +94,8 @@ func handleGithubCallback(w http.ResponseWriter, r *http.Request) {
|
|
}
|
|
}
|
|
|
|
|
|
func getGithubUserInfo(state string, code string) (*githubOauthUser, error) {
|
|
func getGithubUserInfo(state string, code string) (*githubOauthUser, error) {
|
|
- if state != oauth_state_string {
|
|
|
|
|
|
+ oauth_state_string, isValid := logic.IsStateValid(state)
|
|
|
|
+ if !isValid || state != oauth_state_string {
|
|
return nil, fmt.Errorf("invalid OAuth state")
|
|
return nil, fmt.Errorf("invalid OAuth state")
|
|
}
|
|
}
|
|
var token, err = auth_provider.Exchange(context.Background(), code)
|
|
var token, err = auth_provider.Exchange(context.Background(), code)
|