Browse Source

Add authentication managements routes

master
Johan Droz 8 years ago
parent
commit
de225f0ef9
  1. 187
      authentication_management.go

187
authentication_management.go

@ -1,6 +1,9 @@
package keycloak package keycloak
import "gopkg.in/h2non/gentleman.v2/plugins/url" import (
"gopkg.in/h2non/gentleman.v2/plugins/body"
"gopkg.in/h2non/gentleman.v2/plugins/url"
)
const ( const (
authenticationManagementPath = "/auth/admin/realms/:realm/authentication" authenticationManagementPath = "/auth/admin/realms/:realm/authentication"
@ -16,95 +19,171 @@ func (c *Client) GetAuthenticatorProviders(realmName string) ([]map[string]inter
// GetClientAuthenticatorProviders returns a list of client authenticator providers. // GetClientAuthenticatorProviders returns a list of client authenticator providers.
func (c *Client) GetClientAuthenticatorProviders(realmName string) ([]map[string]interface{}, error) { func (c *Client) GetClientAuthenticatorProviders(realmName string) ([]map[string]interface{}, error) {
var resp = []map[string]interface{}{} var resp = []map[string]interface{}{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"client-authenticator-providers"), url.Param("realm", realmName)) var err = c.get(&resp, url.Path(authenticationManagementPath+"/client-authenticator-providers"), url.Param("realm", realmName))
return resp, err return resp, err
} }
// GetAuthenticatorProviderConfig returns the authenticator provider’s configuration description. // GetAuthenticatorProviderConfig returns the authenticator provider’s configuration description.
func (c *Client) GetAuthenticatorProviderConfig(realmName, providerID string) (AuthenticatorConfigInfoRepresentation, error) { func (c *Client) GetAuthenticatorProviderConfig(realmName, providerID string) (AuthenticatorConfigInfoRepresentation, error) {
var resp = AuthenticatorConfigInfoRepresentation{} var resp = AuthenticatorConfigInfoRepresentation{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"config-description/:providerID"), url.Param("realm", realmName), url.Param("providerID", providerID)) var err = c.get(&resp, url.Path(authenticationManagementPath+"/config-description/:providerID"), url.Param("realm", realmName), url.Param("providerID", providerID))
return resp, err return resp, err
} }
// GetAuthenticatorConfig returns the authenticator configuration. // GetAuthenticatorConfig returns the authenticator configuration.
func (c *Client) GetAuthenticatorConfig(realmName, configID string) (AuthenticatorConfigRepresentation, error) { func (c *Client) GetAuthenticatorConfig(realmName, configID string) (AuthenticatorConfigRepresentation, error) {
var resp = AuthenticatorConfigRepresentation{} var resp = AuthenticatorConfigRepresentation{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"config/:id"), url.Param("realm", realmName), url.Param("id", configID)) var err = c.get(&resp, url.Path(authenticationManagementPath+"/config/:id"), url.Param("realm", realmName), url.Param("id", configID))
return resp, err return resp, err
} }
// Update authenticator configuration // UpdateAuthenticatorConfig updates the authenticator configuration.
// PUT /{realm}/authentication/config/{id} func (c *Client) UpdateAuthenticatorConfig(realmName, configID string, config AuthenticatorConfigRepresentation) error {
return c.put(url.Path(authenticationManagementPath+"/config/:id"), url.Param("realm", realmName), url.Param("id", configID), body.JSON(config))
}
// Delete authenticator configuration // DeleteAuthenticatorConfig deletes the authenticator configuration.
// DELETE /{realm}/authentication/config/{id} func (c *Client) DeleteAuthenticatorConfig(realmName, configID string) error {
return c.delete(url.Path(authenticationManagementPath+"/config/:id"), url.Param("realm", realmName), url.Param("id", configID))
}
// Add new authentication execution // CreateAuthenticationExecution add new authentication execution
// POST /{realm}/authentication/executions func (c *Client) CreateAuthenticationExecution(realmName string, authExec AuthenticationExecutionRepresentation) error {
return c.post(url.Path(authenticationManagementPath+"/executions"), url.Param("realm", realmName), body.JSON(authExec))
}
// Delete execution // DeleteAuthenticationExecution deletes the execution.
// DELETE /{realm}/authentication/executions/{executionId} func (c *Client) DeleteAuthenticationExecution(realmName, executionID string) error {
return c.delete(url.Path(authenticationManagementPath+"/executions/:id"), url.Param("realm", realmName), url.Param("id", executionID))
}
// Update execution with new configuration // UpdateAuthenticationExecution update execution with new configuration.
// POST /{realm}/authentication/executions/{executionId}/config func (c *Client) UpdateAuthenticationExecution(realmName, executionID string, authConfig AuthenticatorConfigRepresentation) error {
return c.post(url.Path(authenticationManagementPath+"/executions/:id/config"), url.Param("realm", realmName), url.Param("id", executionID), body.JSON(authConfig))
}
// Lower execution’s priority // LowerExecutionPriority lowers the execution’s priority.
// POST /{realm}/authentication/executions/{executionId}/lower-priority func (c *Client) LowerExecutionPriority(realmName, executionID string) error {
return c.post(url.Path(authenticationManagementPath+"/executions/:id/lower-priority"), url.Param("realm", realmName), url.Param("id", executionID))
}
// Raise execution’s priority // RaiseExecutionPriority raise the execution’s priority.
// POST /{realm}/authentication/executions/{executionId}/raise-priority func (c *Client) RaiseExecutionPriority(realmName, executionID string) error {
return c.post(url.Path(authenticationManagementPath+"/executions/:id/raise-priority"), url.Param("realm", realmName), url.Param("id", executionID))
}
// Create a new authentication flow // CreateAuthenticationFlow creates a new authentication flow.
// POST /{realm}/authentication/flows func (c *Client) CreateAuthenticationFlow(realmName string, authFlow AuthenticationFlowRepresentation) error {
return c.post(url.Path(authenticationManagementPath+"/flows"), url.Param("realm", realmName), body.JSON(authFlow))
}
// Get authentication flows Returns a list of authentication flows. // GetAuthenticationFlows returns a list of authentication flows.
// GET /{realm}/authentication/flows func (c *Client) GetAuthenticationFlows(realmName string) ([]AuthenticationFlowRepresentation, error) {
var resp = []AuthenticationFlowRepresentation{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"/flows"), url.Param("realm", realmName))
return resp, err
}
// Copy existing authentication flow under a new name The new name is given as 'newName' attribute of the passed JSON object // CopyExistingAuthenticationFlow copy the existing authentication flow under a new name.
// POST /{realm}/authentication/flows/{flowAlias}/copy // 'flowAlias' is the name of the existing authentication flow,
// 'newName' is the new name of the authentication flow.
func (c *Client) CopyExistingAuthenticationFlow(realmName, flowAlias, newName string) error {
var m = map[string]string{"newName": newName}
return c.post(url.Path(authenticationManagementPath+"/flows/:flowAlias/copy"), url.Param("realm", realmName), url.Param("flowAlias", flowAlias), body.JSON(m))
}
// Get authentication executions for a flow // GetAuthenticationExecutionForFlow returns the authentication executions for a flow.
// GET /{realm}/authentication/flows/{flowAlias}/executions func (c *Client) GetAuthenticationExecutionForFlow(realmName, flowAlias string) (AuthenticationExecutionInfoRepresentation, error) {
var resp = AuthenticationExecutionInfoRepresentation{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"/flows/:flowAlias/executions"), url.Param("realm", realmName), url.Param("flowAlias", flowAlias))
return resp, err
}
// Update authentication executions of a flow // UpdateAuthenticationExecutionForFlow updates the authentication executions of a flow.
// PUT /{realm}/authentication/flows/{flowAlias}/executions func (c *Client) UpdateAuthenticationExecutionForFlow(realmName, flowAlias string, authExecInfo AuthenticationExecutionInfoRepresentation) error {
return c.put(url.Path(authenticationManagementPath+"/flows/:flowAlias/executions"), url.Param("realm", realmName), url.Param("flowAlias", flowAlias), body.JSON(authExecInfo))
}
// Add new authentication execution to a flow // CreateAuthenticationExecutionForFlow add a new authentication execution to a flow.
// POST /{realm}/authentication/flows/{flowAlias}/executions/execution // 'flowAlias' is the alias of the parent flow.
func (c *Client) CreateAuthenticationExecutionForFlow(realmName, flowAlias, provider string) error {
var m = map[string]string{"provider": provider}
return c.post(url.Path(authenticationManagementPath+"/flows/:flowAlias/executions/execution"), url.Param("realm", realmName), url.Param("flowAlias", flowAlias), body.JSON(m))
}
// Add new flow with new execution to existing flow // CreateFlowWithExecutionForExistingFlow add a new flow with a new execution to an existing flow.
// POST /{realm}/authentication/flows/{flowAlias}/executions/flow // 'flowAlias' is the alias of the parent authentication flow.
func (c *Client) CreateFlowWithExecutionForExistingFlow(realmName, flowAlias, alias, flowType, provider, description string) error {
var m = map[string]string{"alias": alias, "type": flowType, "provider": provider, "description": description}
return c.post(url.Path(authenticationManagementPath+"/flows/:flowAlias/executions/flow"), url.Param("realm", realmName), url.Param("flowAlias", flowAlias), body.JSON(m))
}
// Get authentication flow for id // GetAuthenticationFlow gets the authentication flow for id.
// GET /{realm}/authentication/flows/{id} func (c *Client) GetAuthenticationFlow(realmName, flowID string) (AuthenticationFlowRepresentation, error) {
var resp = AuthenticationFlowRepresentation{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"/flows/:id"), url.Param("realm", realmName), url.Param("id", flowID))
return resp, err
}
// Delete an authentication flow // DeleteAuthenticationFlow deletes an authentication flow.
// DELETE /{realm}/authentication/flows/{id} func (c *Client) DeleteAuthenticationFlow(realmName, flowID string) error {
return c.delete(url.Path(authenticationManagementPath+"/flows/:id"), url.Param("realm", realmName), url.Param("id", flowID))
}
// Get form action providers Returns a list of form action providers. // GetFormActionProviders returns a list of form action providers.
// GET /{realm}/authentication/form-action-providers func (c *Client) GetFormActionProviders(realmName string) ([]map[string]interface{}, error) {
var resp = []map[string]interface{}{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"/form-action-providers"), url.Param("realm", realmName))
return resp, err
}
// Get form providers Returns a list of form providers. // GetFormProviders returns a list of form providers.
// GET /{realm}/authentication/form-providers func (c *Client) GetFormProviders(realmName string) ([]map[string]interface{}, error) {
var resp = []map[string]interface{}{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"/form-providers"), url.Param("realm", realmName))
return resp, err
}
// Get configuration descriptions for all clients // GetConfigDescriptionForClients returns the configuration descriptions for all clients.
// GET /{realm}/authentication/per-client-config-description func (c *Client) GetConfigDescriptionForClients(realmName string) (map[string]interface{}, error) {
var resp = map[string]interface{}{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"/per-client-config-description"), url.Param("realm", realmName))
return resp, err
}
// Register a new required actions // RegisterRequiredAction register a new required action.
// POST /{realm}/authentication/register-required-action func (c *Client) RegisterRequiredAction(realmName, providerID, name string) error {
var m = map[string]string{"providerId": providerID, "name": name}
return c.post(url.Path(authenticationManagementPath+"/register-required-action"), url.Param("realm", realmName), body.JSON(m))
}
// Get required actions Returns a list of required actions. // GetRequiredActions returns a list of required actions.
// GET /{realm}/authentication/required-actions func (c *Client) GetRequiredActions(realmName string) ([]RequiredActionProviderRepresentation, error) {
var resp = []RequiredActionProviderRepresentation{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"/required-actions"), url.Param("realm", realmName))
return resp, err
}
// Get required action for alias // GetRequiredAction returns the required action for the alias.
// GET /{realm}/authentication/required-actions/{alias} func (c *Client) GetRequiredAction(realmName, actionAlias string) (RequiredActionProviderRepresentation, error) {
var resp = RequiredActionProviderRepresentation{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"/required-actions/:alias"), url.Param("realm", realmName), url.Param("alias", actionAlias))
return resp, err
}
// Update required action // UpdateRequiredAction updates the required action.
// PUT /{realm}/authentication/required-actions/{alias} func (c *Client) UpdateRequiredAction(realmName, actionAlias string, action RequiredActionProviderRepresentation) error {
return c.put(url.Path(authenticationManagementPath+"/required-actions/:alias"), url.Param("realm", realmName), url.Param("alias", actionAlias), body.JSON(action))
}
// Delete required action // DeleteRequiredAction deletes the required action.
// DELETE /{realm}/authentication/required-actions/{alias} func (c *Client) DeleteRequiredAction(realmName, actionAlias string) error {
return c.delete(url.Path(authenticationManagementPath+"/required-actions/:alias"), url.Param("realm", realmName), url.Param("alias", actionAlias))
}
// Get unregistered required actions Returns a list of unregistered required actions. // GetUnregisteredRequiredActions returns a list of unregistered required actions.
// GET /{realm}/authentication/unregistered-required-actions func (c *Client) GetUnregisteredRequiredActions(realmName string) ([]map[string]interface{}, error) {
var resp = []map[string]interface{}{}
var err = c.get(&resp, url.Path(authenticationManagementPath+"/unregistered-required-actions"), url.Param("realm", realmName))
return resp, err
}

Loading…
Cancel
Save