improved authentication check

This commit is contained in:
2021-09-24 15:49:51 +02:00
parent ed932e3c92
commit f59f3183f2
4 changed files with 27 additions and 32 deletions

View File

@@ -12,7 +12,6 @@ import (
"github.com/minio/minio-go/v7"
log "github.com/sirupsen/logrus"
errors "git.kapelle.org/niklas/s3browser/internal/errors"
types "git.kapelle.org/niklas/s3browser/internal/types"
)
@@ -114,18 +113,9 @@ func GetParentDir(id string) string {
return NomalizeID(parent)
}
func IsAuth(ctx context.Context) (bool, error) {
func IsAuthenticated(ctx context.Context) bool {
token, ok := ctx.Value("jwt").(*jwt.Token)
if !ok {
return false, errors.ExtendError("UNAUTHORIZED", "Unauthorized")
}
if token.Valid {
return true, nil
} else {
return false, errors.ExtendError("UNAUTHORIZED", "Unauthorized")
}
return (ok && token.Valid)
}
func CreateJWT(claims *types.JWTClaims) *jwt.Token {