Documentation
¶
Index ¶
- Variables
- type APIError
- type Claims
- func (c *Claims) GetAudience() (jwt.ClaimStrings, error)
- func (c *Claims) GetExpirationTime() (*jwt.NumericDate, error)
- func (c *Claims) GetIssuedAt() (*jwt.NumericDate, error)
- func (c *Claims) GetIssuer() (string, error)
- func (c *Claims) GetNotBefore() (*jwt.NumericDate, error)
- func (c *Claims) GetSubject() (string, error)
- type ClientConfig
- type ReCloak
- func (r *ReCloak) Client() *gocloak.GoCloak
- func (r *ReCloak) Config() *ClientConfig
- func (c *ReCloak) DecodeAccessToken(ctx context.Context, tokenString string) (Token, error)
- func (r *ReCloak) GetRepresentation(ctx context.Context) (*gocloak.Client, error)
- func (r *ReCloak) Login(ctx context.Context) error
- func (r *ReCloak) Refresh(ctx context.Context) error
- func (r *ReCloak) RefreshIfExpired(ctx context.Context) error
- func (r *ReCloak) Token() *gocloak.JWT
- type RolesClaim
- type Token
Constants ¶
This section is empty.
Variables ¶
var ( // TokenContextKey is a context key for the token TokenContextKey = tokenContextKey{} // ErrUnauthenticated is returned when the token is not found for a // context. ErrUnauthenticated = errors.New("unauthenticated") // ErrInvalidToken is returned when the token is invalid. ErrInvalidToken = errors.New("invalid token") )
Functions ¶
This section is empty.
Types ¶
type Claims ¶
type Claims struct { jwt.RegisteredClaims // Custom claims PreferredUsername string `json:"preferred_username"` RealmAcess RolesClaim `json:"realm_access,omitempty"` ResourceAcess map[string]RolesClaim `json:"resource_access,omitempty"` }
Claims is a type that represents the claims of a JWT token
func ClaimsFromContext ¶
ClaimsFromContext extracts the claims from the context.
func EnsureClaimsFromContext ¶
EnsureClaimsFromContext extracts the claims from the context or panics.
func (*Claims) GetAudience ¶
func (*Claims) GetExpirationTime ¶
func (*Claims) GetIssuedAt ¶
func (*Claims) GetNotBefore ¶
func (*Claims) GetSubject ¶
type ClientConfig ¶
type ClientConfig struct { AuthServerURL string `yaml:"authServerUrl"` Realm string `yaml:"realm"` ClientID string `yaml:"clientId"` ClientSecret string `yaml:"clientSecret"` }
ClientConfig is a struct to hold Keycloak client configuration.
func NewClientConfigFromURL ¶
func NewClientConfigFromURL(u *url.URL) (*ClientConfig, error)
NewClientConfigFromURL creates a new `ClientConfig` from the given URL.
The URL must have the following format:
<scheme>://<client_id>:<client_secret>@<host>[:<port>]/<realm>
func (*ClientConfig) String ¶
func (c *ClientConfig) String() string
func (*ClientConfig) ToURL ¶
func (c *ClientConfig) ToURL() (*url.URL, error)
ToURL converts the `ClientConfig` to a URL.
func (*ClientConfig) UnmarshalYAML ¶
func (c *ClientConfig) UnmarshalYAML(node *yaml.Node) (err error)
type ReCloak ¶
type ReCloak struct {
// contains filtered or unexported fields
}
ReCloak is a type that provides additional authorization capabilities over `gocloak` library
func NewClient ¶
func NewClient(config *ClientConfig) (*ReCloak, error)
NewClient creates a new ReCloak instance
func (*ReCloak) Client ¶
func (r *ReCloak) Client() *gocloak.GoCloak
Client returns the gocloak client
func (*ReCloak) Config ¶
func (r *ReCloak) Config() *ClientConfig
Config returns the client configuration
func (*ReCloak) DecodeAccessToken ¶
DecodeAccessToken decodes a bearer access token and returns a Token instance
func (*ReCloak) GetRepresentation ¶
Gets client representation from the keycloak server.
func (*ReCloak) RefreshIfExpired ¶
RefreshIfExpired refreshes the token if it is expired
type RolesClaim ¶
type RolesClaim struct {
Roles []string `json:"roles"`
}
RolesClaim is a type that represents the roles claim of a JWT token
func (RolesClaim) HasRole ¶
func (c RolesClaim) HasRole(role string) bool
HasRole checks if the user has the given role.
type Token ¶
type Token struct { *jwt.Token Claims *Claims // Custom claims }
Token is a type that represents a JWT token.
func EnsureTokenFromContext ¶
EnsureTokenFromContext returns a token from the context or panics
func TokenFromContext ¶
TokenFromContext returns a token from the context