Skip to content
Snippets Groups Projects
Unverified Commit 1c48dfdc authored by Jason Knight's avatar Jason Knight Committed by GitHub
Browse files

Try http_key auth method before authorization based auth method in RPC functions. (#772)

parent cc5ba4d9
Branches
Tags
Loading
...@@ -51,25 +51,25 @@ func (s *ApiServer) RpcFuncHttp(w http.ResponseWriter, r *http.Request) { ...@@ -51,25 +51,25 @@ func (s *ApiServer) RpcFuncHttp(w http.ResponseWriter, r *http.Request) {
var username string var username string
var vars map[string]string var vars map[string]string
var expiry int64 var expiry int64
if auth := r.Header["Authorization"]; len(auth) >= 1 { if httpKey := queryParams.Get("http_key"); httpKey != "" {
var token string if httpKey != s.config.GetRuntime().HTTPKey {
userID, username, vars, expiry, token, isTokenAuth = parseBearerAuth([]byte(s.config.GetSession().EncryptionKey), auth[0]) // HTTP key did not match.
if !isTokenAuth || !s.sessionCache.IsValidSession(userID, expiry, token) {
// Auth token not valid or expired.
w.Header().Set("content-type", "application/json") w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusUnauthorized) w.WriteHeader(http.StatusUnauthorized)
_, err := w.Write(authTokenInvalidBytes) _, err := w.Write(httpKeyInvalidBytes)
if err != nil { if err != nil {
s.logger.Debug("Error writing response to client", zap.Error(err)) s.logger.Debug("Error writing response to client", zap.Error(err))
} }
return return
} }
} else if httpKey := queryParams.Get("http_key"); httpKey != "" { } else if auth := r.Header["Authorization"]; len(auth) >= 1 {
if httpKey != s.config.GetRuntime().HTTPKey { var token string
// HTTP key did not match. userID, username, vars, expiry, token, isTokenAuth = parseBearerAuth([]byte(s.config.GetSession().EncryptionKey), auth[0])
if !isTokenAuth || !s.sessionCache.IsValidSession(userID, expiry, token) {
// Auth token not valid or expired.
w.Header().Set("content-type", "application/json") w.Header().Set("content-type", "application/json")
w.WriteHeader(http.StatusUnauthorized) w.WriteHeader(http.StatusUnauthorized)
_, err := w.Write(httpKeyInvalidBytes) _, err := w.Write(authTokenInvalidBytes)
if err != nil { if err != nil {
s.logger.Debug("Error writing response to client", zap.Error(err)) s.logger.Debug("Error writing response to client", zap.Error(err))
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment