Documentation ¶
Index ¶
- func GenerateTokenFromMRT(mrt *models.ModuleRunToken, opts *TokenOpts) (string, error)
- func GenerateTokenFromPAT(pat *models.PersonalAccessToken, opts *TokenOpts) (string, error)
- func GenerateTokenFromWT(wt *models.WorkerToken, opts *TokenOpts) (string, error)
- func GetMRTFromEncoded(tokenString string, repo repository.ModuleRepository, opts *TokenOpts) (*models.ModuleRunToken, error)
- func GetPATFromEncoded(tokenString string, repo repository.PersonalAccessTokenRepository, ...) (*models.PersonalAccessToken, error)
- func GetWTFromEncoded(tokenString string, repo repository.WorkerTokenRepository, opts *TokenOpts) (*models.WorkerToken, error)
- func IsPATValid(tokenString string, repo repository.PersonalAccessTokenRepository, ...) (bool, error)
- type JWTClaimKind
- type JWTClaims
- type TokenOpts
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateTokenFromMRT ¶
func GenerateTokenFromMRT(mrt *models.ModuleRunToken, opts *TokenOpts) (string, error)
GenerateTokenFromMRT creates a new JWT based on a module run token model. Note that the module run token model must include a signing secret and token ID already, otherwise the generation will fail.
func GenerateTokenFromPAT ¶
func GenerateTokenFromPAT(pat *models.PersonalAccessToken, opts *TokenOpts) (string, error)
GenerateTokenFromPAT creates a new JWT based on a personal access token model. Note that the personal access token model must include a signing secret and token ID already, otherwise the generation will fail.
func GenerateTokenFromWT ¶
func GenerateTokenFromWT(wt *models.WorkerToken, opts *TokenOpts) (string, error)
GenerateTokenFromWT creates a new JWT based on a worker token model. Note that the worker token model must include a signing secret and token ID already, otherwise the generation will fail.
func GetMRTFromEncoded ¶
func GetMRTFromEncoded(tokenString string, repo repository.ModuleRepository, opts *TokenOpts) (*models.ModuleRunToken, error)
GetMRTFromEncoded returns a personal access token model based on the raw token. This method performs parsing and validatino on the raw token string, so the returned PAT can be considered valid without additional checks.
func GetPATFromEncoded ¶
func GetPATFromEncoded(tokenString string, repo repository.PersonalAccessTokenRepository, opts *TokenOpts) (*models.PersonalAccessToken, error)
GetPATFromEncoded returns a personal access token model based on the raw token. This method performs parsing and validatino on the raw token string, so the returned PAT can be considered valid without additional checks.
func GetWTFromEncoded ¶
func GetWTFromEncoded(tokenString string, repo repository.WorkerTokenRepository, opts *TokenOpts) (*models.WorkerToken, error)
GetWTFromEncoded returns a worker token model based on the raw token. This method performs parsing and validatino on the raw token string, so the returned token can be considered valid without additional checks.
func IsPATValid ¶
func IsPATValid(tokenString string, repo repository.PersonalAccessTokenRepository, opts *TokenOpts) (bool, error)
IsPATValid parses and validates the raw token. It requires access to the repository because each token gets its own signing secret.
Types ¶
type JWTClaimKind ¶
type JWTClaimKind string
const ( JWTClaimKindPAT JWTClaimKind = "pat" JWTClaimKindMRT JWTClaimKind = "mrt" JWTClaimKindAPI JWTClaimKind = "api" JWTClaimKindWT JWTClaimKind = "wt" )
func GetTokenKind ¶
func GetTokenKind(tokenString string) JWTClaimKind
GetTokenKind returns the type of token being sent. Note that this does NOT validate the token or parse claims.
type JWTClaims ¶
type JWTClaims struct { *jwt.RegisteredClaims // Kind represents the type of JWT token for this server Kind JWTClaimKind `json:"kind"` TokenID string `json:"token_id"` // ServiceAccountUserID is only written when this is a token generated for a service // account ServiceAccountUserID string `json:"sa_user_id"` }
exported for testing purposes. This should NOT be used by callers.