User Management Service

A user management service, with support for configuring roles and permissions.

Operations

Oauth

Roles

Socials

Users

Events

Operations

Oauth


createOauthClient

Create new oauth client.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
name string The client name
redirect string The client redirect url or Callback URL

Responses

Returns created client of given user.

Content: object An oauth client definition

Name Type Description
id integer Oauth client unique ID
name string The client name
secret string The client secret
revoked boolean Is client revoked.
user_id integer User ID
redirect string The client redirect url or Callback URL
created_at string This clent created date time.
updated_at string This clent updated date time.
password_client boolean Is password client.
personal_access_client boolean Is personal access client.
Fail to add.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,-- user_id
  ["name"] = "test client",
  ["redirect"] = "http://test.com.tw/callback"
}
response.message = User.createOauthClient(parameters)

deleteOauthClient

Deletes oauth client from given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
client_id string Client ID

Responses

Oauth client deleted.

Content: nil

Fail to delete.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,-- user_id
  ["client_id"] = 1
}
response.message = User.deleteOauthClient(parameters)

getOauthAuthorizeApproved

authorize approved by given token.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
token string Bearer scheme token authentication defined in https://tools.ietf.org/html/rfc6750
client_id string The oauth client id
redirect_uri string The oauth client redirect url or Callback URL.
response_type string The response type
scope string The scope

Responses

Approved callback URL

Content: string

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local data = {
  ["token"]= token,
  ["client_id"] = request.parameters.client_id,
  ["redirect_uri"] = request.parameters.redirect_uri,
  ["response_type"] = request.parameters.response_type,
  ["scope"] = "profile"
}
local code = encodeURI(tostring(User.getOauthAuthorizeApproved(data)))
local location = request.parameters.redirect_uri .. "?code=" .. code
response.headers["location"] = location
response.code = 303

getOauthClientRedirectPath

Returns oauth client redirect url path(support multiple).

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
client_id string Client ID
redirectIndex integer Redirect url index if you have multiple redirect you can choice default is 0(This is not required)

Responses

URL path

Content: string

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

response.headers["location"] = User.getOauthClientRedirectPath({client_id = request.parameters.client_id,redirectIndex = 0})
response.code = 303

getOauthClients

Returns oauth clients list of given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID

Responses

Oauth clients list retrieved.

Content: object List of oauth clients

Name Type Description
oauth_clients [ object ] Oauth clients
oauth_clients[].id integer Oauth client unique ID
oauth_clients[].name string The client name
oauth_clients[].secret string The client secret
oauth_clients[].revoked boolean Is client revoked.
oauth_clients[].user_id integer User ID
oauth_clients[].redirect string The client redirect url or Callback URL
oauth_clients[].created_at string This clent created date time.
oauth_clients[].updated_at string This clent updated date time.
oauth_clients[].password_client boolean Is password client.
oauth_clients[].personal_access_client boolean Is personal access client.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2 -- user_id
}
response.message = User.getOauthClients(parameters)

getOauthToken

Acquire OAuth tokens with specific credentials. Some arguments are required depending on the grant type. Current support grant types are - 1. authorization_code 2. refresh_token

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
code string The authorization code received from the authorization server. This is required if the given grant_type is 'authorization_code'.
client_id integer Oauth client unique ID
grant_type "authorization_code", "refresh_token" The method to acquire access tokens.
redirect_uri string The client redirect url or Callback URL. This is required if the given grant_type is 'authorization_code'.
client_secret string The client secret
refresh_token string The refresh_token received from the previous token request. This is required if the given grant_type is 'refresh_token'.
access_token_ttl integer {1..} Lifetime of access token in seconds. This is for your application(issuer) to control expiration time, please DO NOT allow your oauth clients to specify this value due to security concerns.
Default: 1296000
refresh_token_ttl integer {1..} Lifetime of refresh token in seconds. This is for your application(issuer) to control expiration time, please DO NOT allow your oauth clients to specify this value due to security concerns.
Default: 31104000

Responses

Oauth Token

Content: object A set of oauth token. Only one set is alive at any moment. Once a new set is created, the old one becomes invalid.

Name Type Description
expires_in integer Token expires time
token_type string Token type
access_token string Access Token
refresh_token string Refresh token
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

-- Example of authorization code grant --
local code = request.body.code
local data = {
  ["client_id"] = request.body.client_id,
  ["client_secret"] = request.body.client_secret,
  ["code"] = code,
  ["grant_type"] = 'authorization_code',
  ["redirect_uri"] = request.body.redirect_uri
}
res =  User.getOauthToken(data)
response.message = res


-- Example of refresh token grant --
local refresh_token = request.body.refresh_token
local data = {
  ["client_id"] = request.body.client_id,
  ["client_secret"] = request.body.client_secret,
  ["refresh_token"] = refresh_token,
  ["grant_type"] = 'refresh_token'
}
res =  User.getOauthToken(data)
response.message = res

updateOauthClient

Updates oauth client of given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
client_id string Client ID
name string The client name
redirect string The client redirect url or Callback URL

Responses

Returns updated client of given user.

Content: object An oauth client definition

Name Type Description
id integer Oauth client unique ID
name string The client name
secret string The client secret
revoked boolean Is client revoked.
user_id integer User ID
redirect string The client redirect url or Callback URL
created_at string This clent created date time.
updated_at string This clent updated date time.
password_client boolean Is password client.
personal_access_client boolean Is personal access client.
Fail to update.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,-- user_id
  ["client_id"] = 1,
  ["name"] = "test client",
  ["redirect"] = "http://test.com.tw/callback"
}
response.message = User.updateOauthClient(parameters)

Roles


addRoleParam

Adds parameter definition to given role.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id string Role ID
body [ object ] List of role parameter definition
body[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)

Responses

Role updated

Content: object A role definition

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameter [ object ] List of role parameter definition
parameter[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
Error message

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["role_id"] = "guest",
  ["body"] = {
    {
      ["name"] = "sn"
    },
    {
      ["name"] = "rid"
    }
  }
}
response.message = User.addRoleParam(parameters)

addRolePerm

Adds permission to given role.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id string Role ID
body [ object ] List of Permissions
body[].method ^[A-Z]{1,10}$ Http method of the endpoint
body[].end_point ^[A-Za-z0-9\-\/_\{\}]{1,150}$ Endpoint path.

Responses

List of role permissions

Content: [ object ] List of Permissions

Name Type Description
method ^[A-Z]{1,10}$ Http method of the endpoint
end_point ^[A-Za-z0-9\-\/_\{\}]{1,150}$ Endpoint path.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["role_id"] = "guest",
  ["body"] = {
    {
      ["method"] = "GET",
      ["end_point"] = "info/{sn}"
    },
    {
      ["method"] = "GET",
      ["end_point"] = "info/{rid}"
    }
  }
}
response.message = User.addRolePerm(parameters)

assignUser

Assigns given roles to given user. Each assignment unit clarifies what value for what property in what role that the user can access.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
roles [ object ] List of user roles
roles[].role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
roles[].parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
roles[].parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
roles[].parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.

Responses

Returns the list of assigned roles of given user.

Content: [ object ] List of user roles

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local param = {
  ["id"] = 2, -- User ID to be assigned to

  ["roles"] = {
    {
      ["role_id"] = "guest",

      -- Assign specific properties for role "guest" to the user. If "parameters" is empty, it is considered that no permission is assigned for this role.

      ["parameters"] = {
        {
          -- Grant the user access to value 1 for property "sn" in role "guest"

          ["name"] = "sn",
          ["value"] = "1"
        },
        {
          -- Grant the user access to value 2 for property "sn" in role "guest"

          ["name"] = "sn",
          ["value"] = "2"
        },
        {
          -- Grant the user access to value 1 for property "rid" in role "guest"

          ["name"] = "rid",
          ["value"] = "1"
        }
      }
    },
    {
      ["role_id"] = "admin",

      -- Assign specific properties for role "admin" to the user. If "parameters" is empty, it is considered that no permission is assigned for this role.

      ["parameters"] = {
        {
          -- Grant the user access to value 999 for property "sn" in role "admin"

          ["name"] = "sn",
          ["value"] = "999"
        }
      }
    }
  }
}
response.message = User.assignUser(param)

createRole

Creates role.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameter [ object ] List of role parameter definition
parameter[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)

Responses

Role created

Content: object A role definition

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameter [ object ] List of role parameter definition
parameter[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
Fail to create role

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local role = {
  ["role_id"] = "guest",
  ["parameter"] = {
    {
      ["name"] = "sn"
    },
    {
      ["name"] = "rid"
    }
  }
}
response.message = User.createRole(role)

deassignUser

Deassigns given role from given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
role_id string Role ID

Responses

Returns the list of assigned roles for the given user.

Content: [ object ] List of user roles

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.
Fail to deassign.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["role_id"] = "guest"
}
response.message = User.deassignUser(parameters)

deassignUserParam

Deassigns given role with specific parameter value from given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
role_id string Role ID
parameter_name string Parameter name
parameter_value string Parameter value

Responses

Returns the list of assigned roles for the given user.

Content: [ object ] List of user roles

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.
Fail to deassign.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["role_id"] = "guest",
  ["parameter_name"] = "sn",
  ["parameter_value"] = "1"
}
respons.message = User.deassignUserParam(parameters)

deassignUserParamName

Deassigns given role with specific parameter name from given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
role_id string Role ID
parameter_name string Parameter name

Responses

Returns the list of assigned roles for the given user.

Content: [ object ] List of user roles

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.
Fail to deassign.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["role_id"] = "guest",
  ["parameter_name"] = "sn"
}
response.message = User.deassignUserParamName(parameters)

deleteRole

Delete given role.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id string Role ID

Responses

Deletion successful

Content: nil

Error message

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["role_id"] = "guest"
}
response.message = User.deleteRole(parameters)

deleteRoleParam

Deletes given role parameter definition.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id string Role ID
parameter_name string Parameter name

Responses

Role updated

Content: object A role definition

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameter [ object ] List of role parameter definition
parameter[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
Error message

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["role_id"] = "guest",
  ["parameter_name"] = "sn"
}
response.message = User.deleteRoleParam(parameters)

deleteRoleParamValue

Deletes given role-parameter value.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id string Role ID
parameter_name string Parameter name
parameter_value string Parameter value

Responses

Deletion successful

Content: nil

Error message

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["role_id"] = "guest",
  ["parameter_name"] = "sn",
  ["parameter_value"] = 1
}
response.message = User.deleteRoleParamValue(parameters)

deleteRolePerm

Deletes permission from given role.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id string Role ID
perm_id string {method}/{end_point}

Responses

List of role permissions

Content: [ object ] List of Permissions

Name Type Description
method ^[A-Z]{1,10}$ Http method of the endpoint
end_point ^[A-Za-z0-9\-\/_\{\}]{1,150}$ Endpoint path.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["role_id"] = "guest",
  ["perm_id"] = "GET/info/{sn}"
}
response.message = User.deleteRolePerm(parameters)

getRole

Gets role by Role ID.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id string Role ID

Responses

Role retrieved

Content: object A role definition

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameter [ object ] List of role parameter definition
parameter[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["role_id"] = "guest"
}
response.message = User.getRole(parameters)

hasUserRoleParam

Checks if given user has given role with specific parameter.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id string Role ID
parameter_name string Parameter name
parameter_value string Parameter value
id string User ID

Responses

"OK" if user has role

Content: "OK"

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["role_id"] = "guest",
  ["parameter_name"] = "sn",
  ["parameter_value"] = "1",
  ["id"] = 2
}
response.message = User.hasUserRoleParam(parameters)

listRoleParamUsers

Returns the list of user IDs in given role with specific parameter.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id string Role ID
parameter_name string Parameter name
parameter_value string Parameter value

Responses

List of user ID

Content: [ integer ]

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["role_id"] = "guest",
  ["parameter_name"] = "sn",
  ["parameter_value"] = "1"
}
response.message = User.listRoleParamUsers(parameters)

listRolePerms

Returns the list of permissions in given role.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id string Role ID

Responses

Role permission list retrieved

Content: [ object ] List of Permissions

Name Type Description
method ^[A-Z]{1,10}$ Http method of the endpoint
end_point ^[A-Za-z0-9\-\/_\{\}]{1,150}$ Endpoint path.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["role_id"] = "guest"
}
response.message = User.listRolePerms(parameters)

listRoleUsers

Returns the list of user IDs in given role.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
role_id string Role ID

Responses

List of user ID

Content: [ integer ]

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["role_id"] = "guest"
}
response.message = User.listRoleUsers(parameters)

listRoles

Returns the list of roles.

Responses

Role list retrieved

Content: [ object ] List of roles

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameter [ object ] List of role parameter definition
parameter[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

response.message = User.listRoles()

listUserRoleParamValues

Returns the paginated list of values of given parameter name belong to given user role.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
role_id string Role ID
parameter_name string Parameter name
offset integer Pagination offset
limit integer {1..100} Pagination limit
Default: 100

Responses

Operation response object containing one page of user role parameters.

Content: object

Name Type Description
items [ string ] One page list of parameters.
total integer Total number of keys.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["role_id"] = "guest",
  ["parameter_name"] = "sn"
}
response.message = User.listUserRoleParamValues(parameters)

listUserRoles

Returns the list of assigned roles of given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID

Responses

User roles list retrieved

Content: [ object ] List of user roles

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

response.message = User.listUserRoles({["id"] = 2})

Socials


createSocial

Add a Social.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
scope [ string ] Specifies the level of access that the application is requesting. Note that different consumers (social login provider) support different scopes. Please refer to official oauth docs for the consumer you use.
e.g. For Facebook, refer to https://developers.facebook.com/docs/facebook-login/permissions/
consumer string Consumer name
redirect string Redirect URI or Callback URL
client_id string Client Identifier
client_secret string Client Authentication

Responses

Social created

Content: object A Social object

Name Type Description
scope [ string ] Specifies the level of access that the application is requesting. Note that different consumers (social login provider) support different scopes. Please refer to official oauth docs for the consumer you use.
e.g. For Facebook, refer to https://developers.facebook.com/docs/facebook-login/permissions/
consumer string Consumer name
redirect string Redirect URI or Callback URL
client_id string Client Identifier
client_secret string Client Authentication
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

-- create a social for Google login
local new_social = {
  ["consumer"] = "Google",
  ["client_id"] = "173032451965-6aritviopipcqec0j4cq5sxc1519m025.apps.googleusercontent.com",
  ["client_secret"] = "sNa2saB31xQnQ09sUc2OOywF",
  ["scope"] = {"profile", "email"}, -- specify the scopes which must be supported by Google provider

  ["redirect"] = "https://demo.apps.exosite-dev.io/social/handle/Google"
}
response.message = User.createSocial(new_social)

deleteSocial

Delete a social.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
consumer string Consumer name

Responses

Social deleted

Content: nil

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["consumer"] = "Google"
}
response.message = User.deleteSocial(parameters)

getSocial

Get social info.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
consumer string Consumer name

Responses

Social info

Content: object A Social object

Name Type Description
scope [ string ] Specifies the level of access that the application is requesting. Note that different consumers (social login provider) support different scopes. Please refer to official oauth docs for the consumer you use.
e.g. For Facebook, refer to https://developers.facebook.com/docs/facebook-login/permissions/
consumer string Consumer name
redirect string Redirect URI or Callback URL
client_id string Client Identifier
client_secret string Client Authentication
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["consumer"] = "Google"
}
response.message = User.getSocial(parameters)

getSocialLoginUrl

Get social login URL.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
consumer string Consumer name
reqToken string The consumer request token

Responses

Consumer login url

Content: string

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["consumer"] = "Google"
}
response.headers["location"] = User.getSocialLoginUrl(parameters) -- redirect to social login url
response.code = 303

getSocialToken

Get social login Token

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
consumer string Consumer name
code string The consumer return code
state string The consumer return state
oauth_token string The consumer return oauth_token
oauth_verifier string The consumer return oauth_verifier
reqToken string The consumer return reqToken

Responses

Social token

Content: string

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["consumer"] = "Google",
  ["code"] = "7/Diur60jCjzCm14ukTdFgxow17OWxzDdj4rA6YQV1Sid",
  ["state"] = "56k120223c83a23b49a136725e63c717"
} -- info from Google servers for exchanging token
response.message = User.getSocialToken(parameters)

socialList

Listing socials.

Responses

List of socials

Content: [ object ]

Name Type Description
scope [ string ] Specifies the level of access that the application is requesting. Note that different consumers (social login provider) support different scopes. Please refer to official oauth docs for the consumer you use.
e.g. For Facebook, refer to https://developers.facebook.com/docs/facebook-login/permissions/
consumer string Consumer name
redirect string Redirect URI or Callback URL
client_id string Client Identifier
client_secret string Client Authentication
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

response.message = User.socialList()

socialRequest

Request social get information

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
consumer string Consumer name
token string The consumer return code

Responses

A social request

Content: string

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["consumer"] = "Google",
  ["token"] = "ZzozMzoiT0F1dGhcT0F1dGgyXFRva2VuXKN0ZE9BdXRoMlRva2VuIjo0OntzOjQ0OiIAKgBhY2Nlc3NUc2tlbiI7czo19ToieWEyOS5DaTlXQTZ1UUFCc3RYSnpmZGhDRjkyZnhaYXRvOURVMEdmTjgwTVRZSTJCbkI1MVptN1pZSjZVbm9vOXEtMktvZVEiO3M6MTU6IgCqAHJlZnJlc2hUb2tlbiI7TjtzOjEyOiIAKgBlbmRPZkxpZmUiO2k6MTQ3MzE1NDYyNztzOjE0OiIAKgBleHRyYVBhcmFtcyI7YToyOntzOjEwOiJ0b2tlbl90eXBlIjtzOjY6IkJTndILU03N2ZacVVVMTZxQlhjSGxILVI2NEVZOG9kVkNnYWM1UkdOVlI5eTA2LUNyeDdPcjlXcm10VmsyYVhMYXFkU3J5c0pqUFREWU5iX2NxM1RrTTFySThnQ1NJT3JhZmE5WHVhaXNtSHhTREtiQmN1bE41YXhCVnF0bFpKWUpUR3BLQmlaeGNGLVREQ1ZZQU5ZaVF4a0lzTjFoVHdlNF9ESzVGNWVaalozdFNzUHR6eGtvZkJBd3U0LWRLeGRWbkM3S25IdGhKLWI1ZVpMenU2aUFIdWRFdEFRckU0WGl6bTM4YkJaRkdRaGFDUVB5R3RXMlRHSTJ2UV9rZkZGbXBiMGFOUUJHTVhLdvkzcFZyR3BvYWpxZFlfZTRfdi13NUxiYXc1RVRuRWdkbmNqNUEi2391"
}
response.message = User.socialRequest(parameters)

updateSocial

Update a social definition.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
consumer string Consumer name
scope [ string ] Specifies the level of access that the application is requesting. Note that different consumers (social login provider) support different scopes. Please refer to official oauth docs for the consumer you use.
e.g. For Facebook, refer to https://developers.facebook.com/docs/facebook-login/permissions/
redirect string Redirect URI or Callback URL
client_id string Client Identifier
client_secret string Client Authentication

Responses

Instance updated

Content: nil

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["consumer"] = "Google",
  ["scope"] = {"email"}
}
response.message = User.updateSocial(parameters)

Users


activateUser

Activates user by given verification code.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
code string The verification code returned from registration.

Responses

"OK" if activation successful

Content: "OK"

User activation failed

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["code"] = "bb48f756e9bf9326d57f63bde70c68dbda90f286"
}
response.message = User.activateUser(parameters)

assignUser

Assigns given roles to given user. Each assignment unit clarifies what value for what property in what role that the user can access.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
roles [ object ] List of user roles
roles[].role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
roles[].parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
roles[].parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
roles[].parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.

Responses

Returns the list of assigned roles of given user.

Content: [ object ] List of user roles

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local param = {
  ["id"] = 2, -- User ID to be assigned to

  ["roles"] = {
    {
      ["role_id"] = "guest",

      -- Assign specific properties for role "guest" to the user. If "parameters" is empty, it is considered that no permission is assigned for this role.

      ["parameters"] = {
        {
          -- Grant the user access to value 1 for property "sn" in role "guest"

          ["name"] = "sn",
          ["value"] = "1"
        },
        {
          -- Grant the user access to value 2 for property "sn" in role "guest"

          ["name"] = "sn",
          ["value"] = "2"
        },
        {
          -- Grant the user access to value 1 for property "rid" in role "guest"

          ["name"] = "rid",
          ["value"] = "1"
        }
      }
    },
    {
      ["role_id"] = "admin",

      -- Assign specific properties for role "admin" to the user. If "parameters" is empty, it is considered that no permission is assigned for this role.

      ["parameters"] = {
        {
          -- Grant the user access to value 999 for property "sn" in role "admin"

          ["name"] = "sn",
          ["value"] = "999"
        }
      }
    }
  }
}
response.message = User.assignUser(param)

createPermission

Adds permission.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
method ^[A-Z]{1,10}$ Http method of the endpoint
end_point ^[A-Za-z0-9\-\/_\{\}]{1,150}$ Endpoint path.

Responses

Permission created

Content: object A permissions definition

Name Type Description
method ^[A-Z]{1,10}$ Http method of the endpoint
end_point ^[A-Za-z0-9\-\/_\{\}]{1,150}$ Endpoint path.
Fail to create permission

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local permission = {
  ["method"] = "GET",
  ["end_point"] = "info/{sn}"
}
response.message = User.createPermission(permission)

createUser

Creates a new user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
name string User name
email string(email) User email
password string User password

Responses

Activation code for the created user

Content: string

Fail to create user

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local user = {
  ["email"] = "guest@exosite.com",
  ["name"] = "guest",
  ["password"] = "demo7Password"
}
response.message = User.createUser(user)

createUserData

Adds key values to given user. New keys and initial values should be put as key-value pairs in parameters object. It requires at least one key-value pair.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
^(?!id$).+$ string {..8192} Values to be written in the key

Responses

Returns current key values of given user.

Content: object Map or key/value properties. Both key and value should be string. Key pattern is [A-Za-z0-9-_]{1,50}

Name Type Description
Fail to add.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["nickname"] = "Demo User" -- new key 'nickname'
}
response.message = User.createUserData(parameters)

deassignUser

Deassigns given role from given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
role_id string Role ID

Responses

Returns the list of assigned roles for the given user.

Content: [ object ] List of user roles

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.
Fail to deassign.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["role_id"] = "guest"
}
response.message = User.deassignUser(parameters)

deassignUserParam

Deassigns given role with specific parameter value from given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
role_id string Role ID
parameter_name string Parameter name
parameter_value string Parameter value

Responses

Returns the list of assigned roles for the given user.

Content: [ object ] List of user roles

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.
Fail to deassign.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["role_id"] = "guest",
  ["parameter_name"] = "sn",
  ["parameter_value"] = "1"
}
respons.message = User.deassignUserParam(parameters)

deassignUserParamName

Deassigns given role with specific parameter name from given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
role_id string Role ID
parameter_name string Parameter name

Responses

Returns the list of assigned roles for the given user.

Content: [ object ] List of user roles

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.
Fail to deassign.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["role_id"] = "guest",
  ["parameter_name"] = "sn"
}
response.message = User.deassignUserParamName(parameters)

deletePerm

Deletes given permission.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
perm_id string {method}/{end_point}

Responses

Deletion successful

Content: nil

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["perm_id"] = "GET/info/{sn}"
}
response.message = User.deletePerm(parameters)

deleteUser

Deletes given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID

Responses

Deletion successful

Content: nil

Fail to delete user

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2
}
response.message = User.deleteUser(parameters)

deleteUserData

Deletes key values from given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
keys [ string ] List of keys

Responses

Returns current key values of given user.

Content: object Map or key/value properties. Both key and value should be string. Key pattern is [A-Za-z0-9-_]{1,50}

Name Type Description
Fail to delete.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["keys"] = {"country", "nickname"}
}
response.message = User.deleteUserData(parameters)

getCurrentUser

Gets user by given token.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
token string Bearer scheme token authentication defined in https://tools.ietf.org/html/rfc6750

Responses

User information retrieved

Content: object A user definition

Name Type Description
id integer User unique ID
name string User name
email string(email) User email
status integer User status
creation_date integer Creation timestamp
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

getUser

Gets user by given User ID.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID

Responses

User retrieved

Content: object A user definition

Name Type Description
id integer User unique ID
name string User name
email string(email) User email
status integer User status
creation_date integer Creation timestamp
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

response.message = User.getUser({["id"] = 2})

getUserData

Returns the value of given key of given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
key string Data key

Responses

The value of given user data key.

Content: string

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["key"] = "birthday"
}
response.message = User.getUserData(parameters)

getUserToken

Gets user's token by email and password.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
email string(email) User email
password string User password
time_to_live integer {1..} Lifetime of token in minutes
Default: 480

Responses

User authentication token

Content: string

Login failed

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["email"] = "guest@exosite.com",
  ["password"] = "demo7Password",
  ["time_to_live"] = 60  -- 1 hour
}
response.message = User.getUserToken(parameters)

hasUserPerm

Checks if given user has given permission. If the end_point of given permission includes variable parameters, it requires specific parameter values.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
perm_id string {method}/{end_point}
parameters [ string ] Given specific parameter values if permission (end_point) has parameters. The syntax of each parameter value is '<parameter_name>::<parameter_value>'.

Responses

Returns "OK" if user has permission

Content: "OK"

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["perm_id"] = "GET/info/{sn}",
  ["parameters"] = {"sn::1"}
}
response.message = User.hasUserPerm(parameters)

listPerms

Returns the list of permissions.

Responses

Permissions retrieved

Content: [ object ] List of Permissions

Name Type Description
method ^[A-Z]{1,10}$ Http method of the endpoint
end_point ^[A-Za-z0-9\-\/_\{\}]{1,150}$ Endpoint path.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

response.message = User.listPerms()

listUserData

Returns key values of given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID

Responses

User properties retrieved

Content: object Map or key/value properties. Both key and value should be string. Key pattern is [A-Za-z0-9-_]{1,50}

Name Type Description
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2
}
response.message = User.listUserData(parameters)

listUserRoleParamValues

Returns the paginated list of values of given parameter name belong to given user role.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
role_id string Role ID
parameter_name string Parameter name
offset integer Pagination offset
limit integer {1..100} Pagination limit
Default: 100

Responses

Operation response object containing one page of user role parameters.

Content: object

Name Type Description
items [ string ] One page list of parameters.
total integer Total number of keys.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["role_id"] = "guest",
  ["parameter_name"] = "sn"
}
response.message = User.listUserRoleParamValues(parameters)

listUserRoles

Returns the list of assigned roles of given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID

Responses

User roles list retrieved

Content: [ object ] List of user roles

Name Type Description
role_id ^[A-Za-z0-9\-_]{1,80}$ Case-insensitive unique ID in roles. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters [ object ] A List of parameters with specific name and value that a user can access in the role.
parameters[].name ^[A-Za-z]{1,40}$ Case-insensitive unique name in roles parameters. Keywords: me, user(s), permission(s), role(s), parameter(s), group(s), member(s)
parameters[].value ^[A-Za-z0-9]{1,100}$ Parameter value, type might be string or object.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

response.message = User.listUserRoles({["id"] = 2})

listUsers

Returns the list of users. Warning! The original response schema is deprecated and will be removed in the future.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
filter [ string ] Filter to limit the result set. The syntax of each clause is '<property_name>::like::<value>'.
offset integer Pagination offset
limit integer {1..100} Pagination limit

Responses

Paginated users

Content: object

Name Type Description
items [ object ] List of users
items[].id integer User unique ID
items[].name string User name
items[].email string(email) User email
items[].status integer User status
items[].creation_date integer Creation timestamp
total integer The total number of user items affected by the query.
Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

-- To paginate users, 'offset' and 'limit' are both required. This example will return paginated users.
local parameters_1 = {
  ["filter"] = {"email::like::guest", "name::like::guest"},
  ["offset"] = 0,
  ["limit"] = 10
}
response.message = User.listUsers(parameters_1)

-- This example will return users from original response schema - a flat list without being wrapped in 'items'.
local parameters_2 = {
  ["filter"] = {"email::like::guest", "name::like::guest"}
}
-- The original response schema is deprecated and will be removed in the future. Please make changes on your current usage by adding input parameters 'offset' and 'limit' always for replacing original response with pagination response.
response.message = User.listUsers(parameters_2)

resetUserPassword

Forces password reset. When a user's password is changed, existing tokens are still valid.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
password ^[\S\s]{8,}$ New password to be set.

Responses

New generated password.

Content: object

Name Type Description
password string New generated password.
Resets successfully.

Content: nil

Error

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["password"] = "newPwd777"
} response.message = User.resetUserPassword(parameters)

updateUser

Updates given user.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
name string User name
status integer {..2} User status. 0: Not Activated 1: Activated 2: Disabled
password string User new password. When a user's password is changed, existing tokens are still valid.
original_password string User original password. Required if updating password.

Responses

User updated

Content: object A user definition

Name Type Description
id integer User unique ID
name string User name
email string(email) User email
status integer User status
creation_date integer Creation timestamp
Fail to update user

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["name"] = "newName"
}
response.message = User.updateUser(parameters)

updateUserData

Updates key values of given user. New values of existing keys should be put as key-value pairs in parameters object. It requires at least one key-value pair.

Arguments

parameters - object - Object containing service call parameters.
Name Type Description
id string User ID
^(?!id$).+$ string {..8192} Values to be written in the key

Responses

Returns current key values of given user.

Content: object Map or key/value properties. Both key and value should be string. Key pattern is [A-Za-z0-9-_]{1,50}

Name Type Description
Fail to update.

Content: object Operation error details

Name Type Description
type string Error type
error string Error message
status integer Response code

Example

local parameters = {
  ["id"] = 2,
  ["country"] = "United States", -- new value 'United States' for existing key 'country'
  ["birthday"] = "1992-08-07" -- new value '1992-08-07' for existing key 'birthday'
}
response.message = User.updateUserData(parameters)

Events


account

This event is triggered by creating/updating/deleting a user or any action causes a change on user-name/user-status/user-password.

Arguments

event - object - Passed info in event 'account'.
Name Type Description
id integer User unique ID
type "CREATE", "UPDATE", "DELETE" User action
email string User email

Example

-- Example of EventHandler script:
-- event
--      .type   'CREATE' | 'DELETE' | 'UPDATE'
--      .id     User ID
--      .email  User email address
if (event.type == 'CREATE') then
  -- handle user create
  -- inform admin via email when a user is created
  local emailData = {
    from = "me@myemail.com",
    to = {
      "admin@email.com"
    },
    subject = "User Creation - "..event.email,
    text = to_json(event),
    html = to_json(event),
    connection = {
      server = "smtp.myemail.com",
      port = 1234,
      user = "me",
      password = "mysecret"
    }
  }
  local result = Email.send(emailData)
end
if (event.type == 'DELETE') then
  -- handle user delete
  -- inform admin via email when a user is updated
  local emailData = {
    from = "me@myemail.com",
    to = {
      "admin@email.com"
    },
    subject = "User Deletion - "..event.email,
    text = to_json(event),
    html = to_json(event),
    connection = {
      server = "smtp.myemail.com",
      port = 1234,
      user = "me",
      password = "mysecret"
    }
  }
  local result = Email.send(emailData)
end
if (event.type == 'UPDATE') then
  -- handle user update
  -- inform admin via email when a user is deleted
  local emailData = {
    from = "me@myemail.com",
    to = {
      "admin@email.com"
    },
    subject = "User Update - "..event.email,
    text = to_json(event),
    html = to_json(event),
    connection = {
      server = "smtp.myemail.com",
      port = 1234,
      user = "me",
      password = "mysecret"
    }
  }
  local result = Email.send(emailData)
end