github.com/zak-blake/goa@v1.4.1/middleware/security/jwt/context.go (about)

     1  package jwt
     2  
     3  import (
     4  	"context"
     5  
     6  	jwt "github.com/dgrijalva/jwt-go"
     7  )
     8  
     9  // WithJWT creates a child context containing the given JWT.
    10  func WithJWT(ctx context.Context, t *jwt.Token) context.Context {
    11  	return context.WithValue(ctx, jwtKey, t)
    12  }
    13  
    14  // ContextJWT retrieves the JWT token from a `context` that went through our security middleware.
    15  func ContextJWT(ctx context.Context) *jwt.Token {
    16  	token, ok := ctx.Value(jwtKey).(*jwt.Token)
    17  	if !ok {
    18  		return nil
    19  	}
    20  	return token
    21  }