mirror of
https://github.com/jc21/nginx-proxy-manager.git
synced 2024-08-30 18:22:48 +00:00
prevent panic when sse token is not found
This commit is contained in:
parent
4dd6fd06f4
commit
3301800f42
@ -29,7 +29,7 @@ func DecodeAuth() func(http.Handler) http.Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
tokenAuth := jwtauth.New("RS256", privateKey, publicKey)
|
tokenAuth := jwtauth.New("RS256", privateKey, publicKey)
|
||||||
return jwtauth.Verify(tokenAuth, jwtauth.TokenFromHeader)
|
return jwtauth.Verify(tokenAuth, jwtauth.TokenFromHeader, jwtauth.TokenFromQuery)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Enforce is a authentication middleware to enforce access from the
|
// Enforce is a authentication middleware to enforce access from the
|
||||||
|
@ -14,13 +14,23 @@ import (
|
|||||||
func SSEAuth(next http.Handler) http.Handler {
|
func SSEAuth(next http.Handler) http.Handler {
|
||||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
ctx := r.Context()
|
ctx := r.Context()
|
||||||
|
|
||||||
token, claims, err := jwtauth.FromContext(ctx)
|
token, claims, err := jwtauth.FromContext(ctx)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
h.ResultErrorJSON(w, r, http.StatusUnauthorized, err.Error(), nil)
|
h.ResultErrorJSON(w, r, http.StatusUnauthorized, err.Error(), nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if token == nil {
|
||||||
|
h.ResultErrorJSON(w, r, http.StatusUnauthorized, "No token given", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if claims != nil {
|
||||||
|
h.ResultErrorJSON(w, r, http.StatusUnauthorized, "Unauthorised", nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
userID := uint(claims["uid"].(float64))
|
userID := uint(claims["uid"].(float64))
|
||||||
_, enabled := user.IsEnabled(userID)
|
_, enabled := user.IsEnabled(userID)
|
||||||
if token == nil || !token.Valid || !enabled || !claims.VerifyIssuer("sse", true) {
|
if token == nil || !token.Valid || !enabled || !claims.VerifyIssuer("sse", true) {
|
||||||
|
Loading…
Reference in New Issue
Block a user