Documentation
¶
Index ¶
- Constants
- Variables
- func DeleteAccessToken(ctx context.Context, provider string, token string) error
- func GenerateToken(userClaims UserClaims, accessPrivateKey []byte, refreshPrivateKey []byte, ...) (string, string, int64, int64, error)
- func GetDefaultGroup(ctx context.Context) (int32, error)
- func GetUserGroups(ctx context.Context) ([]int32, error)
- func IsAuthorizedForGroup(ctx context.Context, groupId int32) bool
- func NewOAuthConfig(provider string, cli bool) (*oauth2.Config, error)
- func NewProviderHttpClient(provider string) *http.Client
- func RegisterOAuthFlags(v *viper.Viper, flags *pflag.FlagSet) error
- func ValidateProviderToken(_ context.Context, provider string, token string) error
- func VerifyRefreshToken(tokenString string, publicKey []byte, store db.Store) (int32, error)
- type RoleInfo
- type UserClaims
Constants ¶
const ( // Google OAuth2 provider Google = "google" // Github OAuth2 provider Github = "github" )
Variables ¶
var OAuthSuccessHtml []byte
OAuthSuccessHtml is the html page sent to the client upon successful enrollment via CLI
var TokenInfoKey struct{}
TokenInfoKey is the key used to store the token info in the context
Functions ¶
func DeleteAccessToken ¶
DeleteAccessToken deletes the access token for a given provider
func GenerateToken ¶
func GenerateToken(userClaims UserClaims, accessPrivateKey []byte, refreshPrivateKey []byte, expiry int64, refreshExpiry int64) (string, string, int64, int64, error)
GenerateToken generates a JWT token
func GetDefaultGroup ¶
GetDefaultGroup returns the default group id for the user
func GetUserGroups ¶
GetUserGroups returns all the groups where an user belongs to
func IsAuthorizedForGroup ¶
IsAuthorizedForGroup returns true if the user is authorized for the given group
func NewOAuthConfig ¶
NewOAuthConfig creates a new OAuth2 config for the given provider and whether the client is a CLI or web client
func NewProviderHttpClient ¶
NewProviderHttpClient creates a new http client for the given provider
func RegisterOAuthFlags ¶
RegisterOAuthFlags registers client ID and secret file flags for all known providers. This is pretty tied into the internal of the auth module, so it lives here, but it would be nice if we have a consistent registration pattern (database flags are registered in the config module).
func ValidateProviderToken ¶
ValidateProviderToken validates the given token for the given provider
Types ¶
type RoleInfo ¶
type RoleInfo struct {
RoleID int32 `json:"role_id"`
IsAdmin bool `json:"is_admin"`
GroupID int32 `json:"group_id"`
OrganizationID int32 `json:"organization_id"`
}
RoleInfo contains the role information for a user
type UserClaims ¶
type UserClaims struct {
UserId int32
GroupIds []int32
Roles []RoleInfo
OrganizationId int32
NeedsPasswordChange bool
}
UserClaims contains the claims for a user
func GetUserClaims ¶
GetUserClaims returns the user claims for the given user
func VerifyToken ¶
VerifyToken verifies the token string and returns the user ID nolint:gocyclo