MCPcopy Create free account
hub / github.com/TheThingsNetwork/lorawan-stack / Verify

Function Verify

pkg/packetbroker/token.go:189–210  ·  view source on GitHub ↗

Verify verifies the token and returns the claims. If issuer is non-empty, the token's issuer must match the issuer. If audience is non-empty, one of the token's audiences must match the audience. The current system timestamp is used as reference to verify not before, issued at and expiry.

(ctx context.Context, token *jwt.JSONWebToken, keyProvider PublicKeyProvider, issuer, audience string)

Source from the content-addressed store, hash-verified

187// If audience is non-empty, one of the token's audiences must match the audience.
188// The current system timestamp is used as reference to verify not before, issued at and expiry.
189func Verify(ctx context.Context, token *jwt.JSONWebToken, keyProvider PublicKeyProvider, issuer, audience string) (TokenClaims, error) {
190 keys, err := keyProvider.PublicKeys(ctx)
191 if err != nil {
192 return TokenClaims{}, err
193 }
194 var claims TokenClaims
195 if err := token.Claims(keys, &claims); err != nil {
196 return TokenClaims{}, errOAuth2Token.WithCause(err)
197 }
198
199 exp := jwt.Expected{
200 Issuer: issuer,
201 Time: time.Now(),
202 }
203 if audience != "" {
204 exp.Audience = jwt.Audience{audience}
205 }
206 if err := claims.Validate(exp); err != nil {
207 return TokenClaims{}, errNotAuthorized.WithCause(err)
208 }
209 return claims, nil
210}
211
212// CachePublicKey caches the result from the given PublicKeyProvider with the TTL.
213func CachePublicKey(provider PublicKeyProvider, ttl time.Duration) PublicKeyProvider {

Callers 2

VerifyNetworkServerMethod · 0.92
ParseAndVerifyFunction · 0.70

Calls 4

PublicKeysMethod · 0.65
NowMethod · 0.65
ValidateMethod · 0.65
WithCauseMethod · 0.45

Tested by

no test coverage detected