keycloak

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2022 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Client GoCloak

	Realm    string
	Username string
	Password string
}

Client interacts with the Keycloak API

func NewClient

func NewClient(host, realm, username, password string) Client

NewClient creates a new Client

func (Client) DeleteGroup

func (c Client) DeleteGroup(ctx context.Context, groupName string) error

DeleteGroup deletes the Keycloak group by name. The method is idempotent and will not do anything if the group does not exits.

func (Client) ListGroups

func (c Client) ListGroups(ctx context.Context) ([]Group, error)

ListGroups returns all Keycloak groups in the realm. This is potentially very expensive, as it needs to iterate over all groups to get their members.

func (Client) PutGroup

func (c Client) PutGroup(ctx context.Context, group Group) (Group, error)

PutGroup creates the provided Keycloak group if it does not exist and adjusts the group members accordingly. The method is idempotent.

type ErrEvent

type ErrEvent string

ErrEvent is the reason this error was thrown. It should be short and unique, imagine people writing switch statements to handle them.

var UserAddError ErrEvent = "AddUserFailed"

UserAddError indicates that the client was unable to add the user to the group

var UserRemoveError ErrEvent = "RemoveUserFailed"

UserRemoveError indicates that the client was unable to remove the user from the group

type GoCloak

type GoCloak interface {
	LoginAdmin(ctx context.Context, username, password, realm string) (*gocloak.JWT, error)
	LogoutUserSession(ctx context.Context, accessToken, realm, session string) error

	CreateGroup(ctx context.Context, accessToken, realm string, group gocloak.Group) (string, error)
	GetGroups(ctx context.Context, accessToken, realm string, params gocloak.GetGroupsParams) ([]*gocloak.Group, error)
	DeleteGroup(ctx context.Context, accessToken, realm, groupID string) error

	GetGroupMembers(ctx context.Context, accessToken, realm, groupID string, params gocloak.GetGroupsParams) ([]*gocloak.User, error)
	GetUsers(ctx context.Context, accessToken, realm string, params gocloak.GetUsersParams) ([]*gocloak.User, error)
	AddUserToGroup(ctx context.Context, token, realm, userID, groupID string) error
	DeleteUserFromGroup(ctx context.Context, token, realm, userID, groupID string) error
}

GoCloak is the subset of methods of the humongous gocloak.GoCloak interface that we actually need. This keeps the mock at a more reasonable size

type Group

type Group struct {
	Name    string
	Members []string
}

Group is a representation of a top level group in keycloak

type MembershipSyncError

type MembershipSyncError struct {
	Err      error
	Username string
	Event    ErrEvent
}

MembershipSyncError is a custom error indicating the failure of syncing the membership of a single user.

func (MembershipSyncError) Error

func (err MembershipSyncError) Error() string

type MembershipSyncErrors

type MembershipSyncErrors []MembershipSyncError

MembershipSyncErrors is a cusom error that can be used to indicate that the client failed to sync one or more memberships.

func (*MembershipSyncErrors) Error

func (errs *MembershipSyncErrors) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳