Documentation
¶
Index ¶
- func WithAdminCredentials(username, password string) testcontainers.CustomizeRequestOption
- func WithImportRealm(realmFile string) testcontainers.CustomizeRequestOption
- type CreateUserRequest
- type KeycloakContainer
- func (k *KeycloakContainer) CreateUser(ctx context.Context, token string, ur CreateUserRequest) 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)
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 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,
"quay.io/keycloak/keycloak:26.0.6-0",
)
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) error
CreateUser creates an enabled user with the provided username. TODO: What to do about realms?
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".