From 9f5a2b117b441cd7a2cc39a8f1a89edb14b8cee6 Mon Sep 17 00:00:00 2001 From: harture <31417989+harture@users.noreply.github.com> Date: Wed, 8 Jan 2020 13:24:28 +0100 Subject: [PATCH] Add recovery code API --- recovery_code.go | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 recovery_code.go diff --git a/recovery_code.go b/recovery_code.go new file mode 100644 index 0000000..f13b98a --- /dev/null +++ b/recovery_code.go @@ -0,0 +1,20 @@ +package keycloak + +import "gopkg.in/h2non/gentleman.v2/plugins/url" +import "gopkg.in/h2non/gentleman.v2/plugins/query" + +const ( + recoveryCodePath = "/auth/realms/:realm/recovery-code" +) + +type RecoveryCodeRepresentation struct { + Code *string `json:"code,omitempty"` +} + +// CreateRecoveryCode creates a new recovery code authenticator and returns the code. +func (c *Client) CreateRecoveryCode(accessToken string, realmName string, userID string) (RecoveryCodeRepresentation, error) { + var resp = RecoveryCodeRepresentation{} + + _, err := c.post(accessToken, &resp, query.Add("userId", userID), url.Path(recoveryCodePath), url.Param("realm", realmName)) + return resp, err +}