Documentation ¶
Index ¶
- func BuildJWT(user string) string
- func BuildJWTWithLabel(user, label string) string
- func BuildJWTWithTime(user, label string, timeValid time.Duration) string
- func CheckTokenValidity(ctx context.Context) (context.Context, error)
- func EnsureValidToken(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, ...) (interface{}, error)
- func EnsureValidTokenStream(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, ...) error
- func IsTimeLeft(tokenStr string, delta time.Duration) bool
- func IsValidUser(user string, authorization []string) bool
- func OauthToken(jwt string) *oauth2.Token
- func ParseValidate(user, tokenStr string) bool
- func SetJWTSecret(jwtSecret string)
- func TokenToContext(ctx context.Context, contextKey interface{}, token *Token) context.Context
- func User(ctx context.Context) string
- type Token
- type UserCtxKey
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BuildJWT ¶
BuildJWT builds a signed JWT token from user string. User string can be user ID, or DID, or something similar. This function is called to generate a token for client. The token is checked with the check function.
func BuildJWTWithLabel ¶
func CheckTokenValidity ¶
CheckTokenValidity check if context includes valid JWT and if so, wraps a new one with valid user ID.
func EnsureValidToken ¶
func EnsureValidToken(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error)
EnsureValidToken ensures a valid token exists within a request's metadata. If the token is missing or invalid, the interceptor blocks execution of the handler and returns an error. Otherwise, the interceptor invokes the unary handler.
func EnsureValidTokenStream ¶
func EnsureValidTokenStream(srv interface{}, ss grpc.ServerStream, info *grpc.StreamServerInfo, handler grpc.StreamHandler) error
EnsureValidTokenStream ensures a valid token exists within a request's metadata. If the token is missing or invalid, the interceptor blocks execution of the handler and returns an error. Otherwise, the interceptor invokes the unary handler.
func IsTimeLeft ¶
IsTimeLeft calculates if time is left in token with given duration.
func IsValidUser ¶
IsValidUser loops thru the authorization and checks that correct user is in the Bearer JWT token.
func OauthToken ¶
OauthToken returns our JWT token as an oauth because it helps wrapping it to gRPC credentials.
func ParseValidate ¶
ParseValidate validates the JWT token and that cheks it contains the correct the Username.
func SetJWTSecret ¶
func SetJWTSecret(jwtSecret string)
func TokenToContext ¶
TokenToContext stores user data from raw token to context Used with tests
Types ¶
type UserCtxKey ¶
type UserCtxKey string
UserCtxKey is type for key to access user value from context. It's currently exported for possible outside use.