Files
ocis/ocis-pkg/keycloak/types.go
David WalterandClaude Opus 4.8 5a23c88296 feat(invitations): configurable Keycloak required actions and working ocis_full SMTP (#12467)
* feat(invitations): configurable Keycloak actions + working ocis_full SMTP

The invitations service already triggers Keycloak execute-actions-email after
provisioning a guest (service.Invite -> backend.SendMail ->
gocloak.ExecuteActionsEmail). Two things still limited it:

- The required actions were hardcoded to UPDATE_PASSWORD,VERIFY_EMAIL. They are
  now configurable via INVITATIONS_KEYCLOAK_EXECUTE_ACTIONS (comma-separated,
  same default). Unknown actions are logged and skipped, and the service falls
  back to the defaults if none remain valid so a guest always has a setup path.

- The Keycloak realm shipped with the ocis_full example had an empty smtpServer,
  so Keycloak silently dropped every mail it tried to send, including the guest
  invitation mail. The realm now points SMTP at the bundled mailpit
  (mailserver:1025).

Verified: execute-actions-email delivers to mailpit against the ocis_full realm;
go test ./services/invitations/... ./ocis-pkg/keycloak/... -race passes.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: David Walter <david.walter@kiteworks.com>

* fix(invitations): return the created user as invitedUser in the response

service.Invite echoed the request body unchanged, leaving the invitedUser
relation of the Graph invitation response empty, so a client could not learn
the identity of the guest that was just created. The keycloak backend now
records the created user (OWNCLOUD_ID, email, user type) on the invitation.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: David Walter <david.walter@kiteworks.com>

* refactor(invitations): pass Keycloak actions through verbatim (no allowlist)

Address review (@kobergj): the configured execute-actions no longer need to
match a hardcoded enum. UserAction is now a string type passed to Keycloak
as-is, so operators can configure any required action their Keycloak supports
without oCIS keeping a list in sync. The convenience constants remain, the
default (UPDATE_PASSWORD, VERIFY_EMAIL) is unchanged, and validation is left to
Keycloak. Removes UserActionFromString and the two lookup maps.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Signed-off-by: David Walter <david.walter@kiteworks.com>

---------

Signed-off-by: David Walter <david.walter@kiteworks.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-31 15:54:23 +02:00

55 lines
2.8 KiB
Go

package keycloak
import (
"context"
"github.com/Nerzal/gocloak/v13"
libregraph "github.com/owncloud/libre-graph-api-go"
)
// UserAction is a Keycloak required-action provider ID. It is a free-form
// string so operators can configure any action Keycloak supports; it is passed
// to Keycloak verbatim. The constants below are the common built-ins, provided
// for convenience only - the list does not need to be exhaustive or kept in
// sync with Keycloak.
type UserAction string
const (
// UserActionUpdatePassword sets it that the user needs to change their password.
UserActionUpdatePassword UserAction = "UPDATE_PASSWORD"
// UserActionVerifyEmail sets it that the user needs to verify their email address.
UserActionVerifyEmail UserAction = "VERIFY_EMAIL"
// UserActionUpdateProfile sets it that the user needs to update their profile.
UserActionUpdateProfile UserAction = "UPDATE_PROFILE"
// UserActionConfigureTOTP sets it that the user needs to configure a one-time password.
UserActionConfigureTOTP UserAction = "CONFIGURE_TOTP"
// UserActionTermsAndConditions sets it that the user needs to accept the terms and conditions.
UserActionTermsAndConditions UserAction = "TERMS_AND_CONDITIONS"
// UserActionVerifyProfile sets it that the user needs to verify their profile.
UserActionVerifyProfile UserAction = "VERIFY_PROFILE"
// UserActionDeleteAccount sets it that the user is allowed to delete their account.
UserActionDeleteAccount UserAction = "delete_account"
// UserActionUpdateLocale sets it that the user needs to update their locale.
UserActionUpdateLocale UserAction = "update_user_locale"
// UserActionWebauthnRegister sets it that the user needs to register a WebAuthn authenticator.
UserActionWebauthnRegister UserAction = "webauthn-register"
// UserActionWebauthnRegisterPasswordless sets it that the user needs to register a passwordless WebAuthn authenticator.
UserActionWebauthnRegisterPasswordless UserAction = "webauthn-register-passwordless"
// UserActionConfigureRecoveryAuthnCodes sets it that the user needs to configure recovery authentication codes.
UserActionConfigureRecoveryAuthnCodes UserAction = "CONFIGURE_RECOVERY_AUTHN_CODES"
)
// PIIReport is a structure of all the PersonalIdentifiableInformation contained in keycloak.
type PIIReport struct {
UserData *libregraph.User
Sessions []*gocloak.UserSessionRepresentation
}
// Client represents a keycloak client.
type Client interface {
CreateUser(ctx context.Context, realm string, user *libregraph.User, userActions []UserAction) (string, error)
SendActionsMail(ctx context.Context, realm, userID string, userActions []UserAction) error
GetUserByUsername(ctx context.Context, realm, username string) (*libregraph.User, error)
GetPIIReport(ctx context.Context, realm, username string) (*PIIReport, error)
}