Documentation
¶
Index ¶
- func WithAdminCredentials(username, password string) testcontainers.CustomizeRequestOption
- func WithImportRealm(realmFile string) testcontainers.CustomizeRequestOption
- type CreateUserRequest
- type CredentialRepresentation
- type KeycloakContainer
- func (k *KeycloakContainer) CreateUser(ctx context.Context, token string, ur CreateUserRequest) (string, error)
- func (k *KeycloakContainer) EnableUnmanagedAttributes(ctx context.Context, token string) error
- func (k *KeycloakContainer) EndpointPath(ctx context.Context, path string) (string, error)
- func (k *KeycloakContainer) GetBearerToken(ctx context.Context, username, password string) (string, error)
- func (k *KeycloakContainer) SetUserPassword(ctx context.Context, token, userID, password string) error
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithAdminCredentials ¶
func WithAdminCredentials(username, password string) testcontainers.CustomizeRequestOption
WithAdminCredentials sets the admin username and password.
func WithImportRealm ¶
func WithImportRealm(realmFile string) testcontainers.CustomizeRequestOption
WithImportRealm sets the container up to read from a Realm export.
Types ¶
type CreateUserRequest ¶
type CreateUserRequest struct {
Username string `json:"username"`
Enabled bool `json:"enabled"`
Firstname string `json:"firstName,omitempty"`
Lastname string `json:"lastName,omitempty"`
Email string `json:"email,omitempty"`
EmailVerified bool `json:"emailVerified"`
Attributes map[string][]string `json:"attributes,omitempty"`
}
CreateUserRequest provides fields for creating users.
type CredentialRepresentation ¶ added in v0.0.4
type CredentialRepresentation struct {
Algorithm string `json:"algorithm,omitempty"`
Counter int32 `json:"counter,omitempty"`
Device string `json:"device,omitempty"`
Digits int32 `json:"digits,omitempty"`
HashedSaltedValue string `json:"hashedSaltedValue,omitempty"`
HashIterations int32 `json:"hashIterations,omitempty"`
Period int32 `json:"period,omitempty"`
Salt string `json:"salt,omitempty"`
Temporary *bool `json:"temporary,omitempty"`
Type string `json:"type,omitempty"`
Value string `json:"value,omitempty"`
}
CredentialRepresentation represents credentials for a user or client TODO: Custom unmarshal timestamps from Keycloak!
Converted from https://www.keycloak.org/docs-api/latest/rest-api/index.html#CredentialRepresentation
type KeycloakContainer ¶
type KeycloakContainer struct {
testcontainers.Container
}
KeycloakContainer executes Keycloak and provides additional functionality for interacting with a running Keycloak server.
func Run ¶
func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustomizer) (*KeycloakContainer, error)
Run creates an instance of the Keycloak container type.
Example ¶
ctx := context.Background()
keycloakContainer, err := keycloak.Run(ctx,
testImage,
)
defer func() {
if err := testcontainers.TerminateContainer(keycloakContainer); err != nil {
log.Printf("failed to terminate container: %s", err)
}
}()
if err != nil {
log.Printf("failed to start container: %s", err)
return
}
// }
state, err := keycloakContainer.State(ctx)
if err != nil {
log.Printf("failed to get container state: %s", err)
return
}
fmt.Println(state.Running)
Output: true
func (*KeycloakContainer) CreateUser ¶
func (k *KeycloakContainer) CreateUser(ctx context.Context, token string, ur CreateUserRequest) (string, error)
CreateUser creates an enabled user with the provided username. TODO: What to do about realms?
Returns the UUID of the created user.
func (*KeycloakContainer) EnableUnmanagedAttributes ¶ added in v0.0.3
func (k *KeycloakContainer) EnableUnmanagedAttributes(ctx context.Context, token string) error
EnableUnmanagedAttributes modifies the realm to allow unmanaged attributes.
func (*KeycloakContainer) EndpointPath ¶
EndpointPath returns a URL that is relative to the container endpoint. The path must be fully qualified e.g. /admin/realms/master/users
func (*KeycloakContainer) GetBearerToken ¶
func (k *KeycloakContainer) GetBearerToken(ctx context.Context, username, password string) (string, error)
GetBearerToken makes a call to the OpenID endpoint to request a token.
The request is authenticated with the provided username/password.
The client_id defaults to "admin-cli".
func (*KeycloakContainer) SetUserPassword ¶ added in v0.0.4
func (k *KeycloakContainer) SetUserPassword(ctx context.Context, token, userID, password string) error
SetUserPassword sets a user password. TODO: What to do about realms? https://www.keycloak.org/docs-api/latest/rest-api/index.html#_put_adminrealmsrealmusersuser_idreset_password