Replace "GET", "POST" to http.MethodGet and http.MethodPost
This commit is contained in:
		@@ -261,7 +261,7 @@ func (a *app) handleCallback(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
	ctx := oidc.ClientContext(r.Context(), a.client)
 | 
						ctx := oidc.ClientContext(r.Context(), a.client)
 | 
				
			||||||
	oauth2Config := a.oauth2Config(nil)
 | 
						oauth2Config := a.oauth2Config(nil)
 | 
				
			||||||
	switch r.Method {
 | 
						switch r.Method {
 | 
				
			||||||
	case "GET":
 | 
						case http.MethodGet:
 | 
				
			||||||
		// Authorization redirect callback from OAuth2 auth flow.
 | 
							// Authorization redirect callback from OAuth2 auth flow.
 | 
				
			||||||
		if errMsg := r.FormValue("error"); errMsg != "" {
 | 
							if errMsg := r.FormValue("error"); errMsg != "" {
 | 
				
			||||||
			http.Error(w, errMsg+": "+r.FormValue("error_description"), http.StatusBadRequest)
 | 
								http.Error(w, errMsg+": "+r.FormValue("error_description"), http.StatusBadRequest)
 | 
				
			||||||
@@ -277,7 +277,7 @@ func (a *app) handleCallback(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		token, err = oauth2Config.Exchange(ctx, code)
 | 
							token, err = oauth2Config.Exchange(ctx, code)
 | 
				
			||||||
	case "POST":
 | 
						case http.MethodPost:
 | 
				
			||||||
		// Form request from frontend to refresh a token.
 | 
							// Form request from frontend to refresh a token.
 | 
				
			||||||
		refresh := r.FormValue("refresh_token")
 | 
							refresh := r.FormValue("refresh_token")
 | 
				
			||||||
		if refresh == "" {
 | 
							if refresh == "" {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -240,7 +240,7 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
	showBacklink := len(s.connectors) > 1
 | 
						showBacklink := len(s.connectors) > 1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch r.Method {
 | 
						switch r.Method {
 | 
				
			||||||
	case "GET":
 | 
						case http.MethodGet:
 | 
				
			||||||
		switch conn := conn.Connector.(type) {
 | 
							switch conn := conn.Connector.(type) {
 | 
				
			||||||
		case connector.CallbackConnector:
 | 
							case connector.CallbackConnector:
 | 
				
			||||||
			// Use the auth request ID as the "state" token.
 | 
								// Use the auth request ID as the "state" token.
 | 
				
			||||||
@@ -285,7 +285,7 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
		default:
 | 
							default:
 | 
				
			||||||
			s.renderError(w, http.StatusBadRequest, "Requested resource does not exist.")
 | 
								s.renderError(w, http.StatusBadRequest, "Requested resource does not exist.")
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case "POST":
 | 
						case http.MethodPost:
 | 
				
			||||||
		passwordConnector, ok := conn.Connector.(connector.PasswordConnector)
 | 
							passwordConnector, ok := conn.Connector.(connector.PasswordConnector)
 | 
				
			||||||
		if !ok {
 | 
							if !ok {
 | 
				
			||||||
			s.renderError(w, http.StatusBadRequest, "Requested resource does not exist.")
 | 
								s.renderError(w, http.StatusBadRequest, "Requested resource does not exist.")
 | 
				
			||||||
@@ -323,12 +323,12 @@ func (s *Server) handleConnectorLogin(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
func (s *Server) handleConnectorCallback(w http.ResponseWriter, r *http.Request) {
 | 
					func (s *Server) handleConnectorCallback(w http.ResponseWriter, r *http.Request) {
 | 
				
			||||||
	var authID string
 | 
						var authID string
 | 
				
			||||||
	switch r.Method {
 | 
						switch r.Method {
 | 
				
			||||||
	case "GET": // OAuth2 callback
 | 
						case http.MethodGet: // OAuth2 callback
 | 
				
			||||||
		if authID = r.URL.Query().Get("state"); authID == "" {
 | 
							if authID = r.URL.Query().Get("state"); authID == "" {
 | 
				
			||||||
			s.renderError(w, http.StatusBadRequest, "User session error.")
 | 
								s.renderError(w, http.StatusBadRequest, "User session error.")
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case "POST": // SAML POST binding
 | 
						case http.MethodPost: // SAML POST binding
 | 
				
			||||||
		if authID = r.PostFormValue("RelayState"); authID == "" {
 | 
							if authID = r.PostFormValue("RelayState"); authID == "" {
 | 
				
			||||||
			s.renderError(w, http.StatusBadRequest, "User session error.")
 | 
								s.renderError(w, http.StatusBadRequest, "User session error.")
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
@@ -366,14 +366,14 @@ func (s *Server) handleConnectorCallback(w http.ResponseWriter, r *http.Request)
 | 
				
			|||||||
	var identity connector.Identity
 | 
						var identity connector.Identity
 | 
				
			||||||
	switch conn := conn.Connector.(type) {
 | 
						switch conn := conn.Connector.(type) {
 | 
				
			||||||
	case connector.CallbackConnector:
 | 
						case connector.CallbackConnector:
 | 
				
			||||||
		if r.Method != "GET" {
 | 
							if r.Method != http.MethodGet {
 | 
				
			||||||
			s.logger.Errorf("SAML request mapped to OAuth2 connector")
 | 
								s.logger.Errorf("SAML request mapped to OAuth2 connector")
 | 
				
			||||||
			s.renderError(w, http.StatusBadRequest, "Invalid request")
 | 
								s.renderError(w, http.StatusBadRequest, "Invalid request")
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		identity, err = conn.HandleCallback(parseScopes(authReq.Scopes), r)
 | 
							identity, err = conn.HandleCallback(parseScopes(authReq.Scopes), r)
 | 
				
			||||||
	case connector.SAMLConnector:
 | 
						case connector.SAMLConnector:
 | 
				
			||||||
		if r.Method != "POST" {
 | 
							if r.Method != http.MethodPost {
 | 
				
			||||||
			s.logger.Errorf("OAuth2 request mapped to SAML connector")
 | 
								s.logger.Errorf("OAuth2 request mapped to SAML connector")
 | 
				
			||||||
			s.renderError(w, http.StatusBadRequest, "Invalid request")
 | 
								s.renderError(w, http.StatusBadRequest, "Invalid request")
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
@@ -446,7 +446,7 @@ func (s *Server) handleApproval(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	switch r.Method {
 | 
						switch r.Method {
 | 
				
			||||||
	case "GET":
 | 
						case http.MethodGet:
 | 
				
			||||||
		if s.skipApproval {
 | 
							if s.skipApproval {
 | 
				
			||||||
			s.sendCodeResponse(w, r, authReq)
 | 
								s.sendCodeResponse(w, r, authReq)
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
@@ -460,7 +460,7 @@ func (s *Server) handleApproval(w http.ResponseWriter, r *http.Request) {
 | 
				
			|||||||
		if err := s.templates.approval(w, authReq.ID, authReq.Claims.Username, client.Name, authReq.Scopes); err != nil {
 | 
							if err := s.templates.approval(w, authReq.ID, authReq.Claims.Username, client.Name, authReq.Scopes); err != nil {
 | 
				
			||||||
			s.logger.Errorf("Server template error: %v", err)
 | 
								s.logger.Errorf("Server template error: %v", err)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	case "POST":
 | 
						case http.MethodPost:
 | 
				
			||||||
		if r.FormValue("approval") != "approve" {
 | 
							if r.FormValue("approval") != "approve" {
 | 
				
			||||||
			s.renderError(w, http.StatusInternalServerError, "Approval rejected.")
 | 
								s.renderError(w, http.StatusInternalServerError, "Approval rejected.")
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -137,7 +137,7 @@ func checkHTTPErr(r *http.Response, validStatusCodes ...int) error {
 | 
				
			|||||||
	if r.StatusCode == http.StatusNotFound {
 | 
						if r.StatusCode == http.StatusNotFound {
 | 
				
			||||||
		return storage.ErrNotFound
 | 
							return storage.ErrNotFound
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	if r.Request.Method == "POST" && r.StatusCode == http.StatusConflict {
 | 
						if r.Request.Method == http.MethodPost && r.StatusCode == http.StatusConflict {
 | 
				
			||||||
		return storage.ErrAlreadyExists
 | 
							return storage.ErrAlreadyExists
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user