MCPcopy Create free account
hub / github.com/chainloop-dev/chainloop / verifyAndMarshalJWT

Function verifyAndMarshalJWT

app/artifact-cas/internal/server/grpc.go:191–216  ·  view source on GitHub ↗

verifyAndMarshalJWT verifies the token and returns the claims

(token string, keyFunc jwt.Keyfunc, signingMethod jwt.SigningMethod)

Source from the content-addressed store, hash-verified

189
190// verifyAndMarshalJWT verifies the token and returns the claims
191func verifyAndMarshalJWT(token string, keyFunc jwt.Keyfunc, signingMethod jwt.SigningMethod) (*casJWT.Claims, error) {
192 var tokenInfo *jwt.Token
193 claims := &casJWT.Claims{}
194
195 tokenInfo, err := jwt.ParseWithClaims(token, claims, keyFunc)
196 if err != nil {
197 switch {
198 case errors.Is(err, jwt.ErrTokenMalformed):
199 return nil, jwtMiddleware.ErrTokenInvalid
200 case errors.Is(err, jwt.ErrTokenExpired), errors.Is(err, jwt.ErrTokenNotValidYet):
201 return nil, jwtMiddleware.ErrTokenExpired
202 default:
203 return nil, errors.Unauthorized("UNAUTHORIZED", err.Error())
204 }
205 }
206
207 if !tokenInfo.Valid {
208 return nil, jwtMiddleware.ErrTokenInvalid
209 }
210
211 if tokenInfo.Method != signingMethod {
212 return nil, jwtMiddleware.ErrUnSupportSigningMethod
213 }
214
215 return claims, nil
216}

Callers 1

jwtAuthFuncFunction · 0.70

Calls 1

ErrorMethod · 0.65

Tested by

no test coverage detected