|
@@ -8,6 +8,7 @@ import (
|
|
|
"github.com/lestrrat-go/jwx/jwt"
|
|
|
|
|
|
"github.com/drakkan/sftpgo/logger"
|
|
|
+ "github.com/drakkan/sftpgo/utils"
|
|
|
)
|
|
|
|
|
|
type ctxKeyConnAddr int
|
|
@@ -37,6 +38,11 @@ func jwtAuthenticator(next http.Handler) http.Handler {
|
|
|
sendAPIResponse(w, r, err, http.StatusText(http.StatusUnauthorized), http.StatusUnauthorized)
|
|
|
return
|
|
|
}
|
|
|
+ if !utils.IsStringInSlice(tokenAudienceAPI, token.Audience()) {
|
|
|
+ logger.Debug(logSender, "", "the token audience is not valid")
|
|
|
+ sendAPIResponse(w, r, nil, "Your token audience is not valid", http.StatusUnauthorized)
|
|
|
+ return
|
|
|
+ }
|
|
|
if isTokenInvalidated(r) {
|
|
|
logger.Debug(logSender, "", "the token has been invalidated")
|
|
|
sendAPIResponse(w, r, nil, "Your token is no longer valid", http.StatusUnauthorized)
|
|
@@ -64,6 +70,11 @@ func jwtAuthenticatorWeb(next http.Handler) http.Handler {
|
|
|
http.Redirect(w, r, webLoginPath, http.StatusFound)
|
|
|
return
|
|
|
}
|
|
|
+ if !utils.IsStringInSlice(tokenAudienceWeb, token.Audience()) {
|
|
|
+ logger.Debug(logSender, "", "the token audience is not valid")
|
|
|
+ http.Redirect(w, r, webLoginPath, http.StatusFound)
|
|
|
+ return
|
|
|
+ }
|
|
|
if isTokenInvalidated(r) {
|
|
|
logger.Debug(logSender, "", "the token has been invalidated")
|
|
|
http.Redirect(w, r, webLoginPath, http.StatusFound)
|