FusionAuth.Users (FusionAuth v0.3.0) View Source
The FusionAuth.Users
module provides access functions to the FusionAuth Users API.
All functions require a Tesla Client struct created with FusionAuth.client(base_url, api_key, tenant_id)
.
User Fields
token :: String.t()
The access token, this string is an encoded JSON Web Token (JWT).
active :: boolean()
True if the User is active. False if the User has been deactivated. Deactivated Users will not be able to login.
birthDate :: String.t()
The User’s birthdate formatted as
YYYY-MM-DD
.cleanSpeakId :: String.t()
This Id is used by FusionAuth when the User’s username is sent to CleanSpeak to be moderated (filtered and potentially sent to the approval queue). It is the content Id of the username inside CleanSpeak.
data :: map()
An object that can hold any information about the User that should be persisted.
email :: String.t()
The User’s email address.
expiry :: integer()
The expiration instant of the User’s account. An expired user is not permitted to login.
firstName :: String.t()
The first name of the User.
fullName :: String.t()
The User’s full name as a separate field that is not calculated from
firstName
andlastName
.id :: String.t()
The User's unique Id.
imageUrl :: String.t()
The URL that points to an image file that is the User’s profile image.
insertInstant :: integer()
The instant when user was created.
lastLoginInstant :: integer()
The instant when the User logged in last.
lastName :: String.t()
The User's last name.
middleName :: String.t()
The User's middle name.
mobilePhone :: String.t()
The User’s mobile phone number. This is useful is you will be sending push notifications or SMS messages to the User.
parentEmail :: String.t()
The email address of the user’s parent or guardian. If this value was provided during a create or update operation, this value value will only remain until the child is claimed by a parent.
passwordChangeRequired :: boolean()
Indicates that the User’s password needs to be changed during their next login attempt.
passwordLastUpdateInstant :: integer()
The instant that the User last changed their password.
preferredLanguages :: list()
An array of locale strings that give, in order, the User’s preferred languages. These are important for email templates and other localizable text. See Locales.
registrations :: list()
The list of registrations for the User.
tenantId :: String.t()
The Id of the Tenant that this User belongs to.
timezone :: String.t()
The User’s preferred timezone. This can be used as a default to display instants, and it is recommended that you allow User’s to change this per-session. The string will be in an IANA time zone format.
twoFactorDelivery :: String.t()
The User’s preferred delivery for verification codes during a two factor login request.
twoFactorEnabled :: boolean()
Determines if the User has two factor authentication enabled for their account or not.
username :: String.t()
The username of the User.
usernameStatus :: String.t()
The current status of the username. This is used if you are moderating usernames via CleanSpeak.
verified :: boolean()
Whether or not the User’s email has been verified.
Examples
iex> client = FusionAuth.client("http://localhost:9011", "sQ9wwELaI0whHQqyQUxAJmZvVzZqUL-hpfmAmPgbIu8", "6b40f9d6-cfd8-4312-bff8-b082ad45e93c")
iex> FusionAuth.Users.get_user_by_id(client, "06da543e-df3e-4011-b122-a9ff04326599")
{:ok,
%{
"user" => %{
"active" => true,
"email" => "cogadmin@cogility.com",
"firstName" => "Cogility",
"fullName" => "Cogility Admin",
"id" => "06da543e-df3e-4011-b122-a9ff04326599",
"insertInstant" => 1590606624689,
"lastLoginInstant" => 1591138635342,
"lastName" => "Admin",
"memberships" => [
%{
"groupId" => "6f0a1769-21f3-4705-a653-bd66c3ff6a63",
"id" => "ff6fea80-31a3-439b-b880-def21933a01d",
"insertInstant" => 1590705735370
}
],
"mobilePhone" => "6092895176",
"passwordChangeRequired" => false,
"passwordLastUpdateInstant" => 1590606624715,
"preferredLanguages" => ["en"],
"registrations" => [
%{
"applicationId" => "f8109431-14f2-4815-9987-77fdedeff802",
"id" => "7aaad5c8-846d-4a40-b587-fa62f0e6240e",
"insertInstant" => 1590606684278,
"lastLoginInstant" => 1591138635342,
"preferredLanguages" => ["en"],
"roles" => ["admin", "user"],
"timezone" => "America/Los_Angeles",
"username" => "cogadmin",
"usernameStatus" => "ACTIVE",
"verified" => true
}
],
"tenantId" => "6b40f9d6-cfd8-4312-bff8-b082ad45e93c",
"timezone" => "America/Los_Angeles",
"twoFactorDelivery" => "None",
"twoFactorEnabled" => false,
"username" => "cogadmin",
"usernameStatus" => "ACTIVE",
"verified" => true
}
},
%Tesla.Env{
__client__: %Tesla.Client{
adapter: {Tesla.Adapter.Hackney, :call, [[recv_timeout: 30000]]},
fun: nil,
post: [],
pre: [
{Tesla.Middleware.BaseUrl, :call, ["http://localhost:9011"]},
{Tesla.Middleware.JSON, :call, [[]]},
{Tesla.Middleware.Headers, :call,
[
[
{"Authorization", "sQ9wwELaI0whHQqyQUxAJmZvVzZqUL-hpfmAmPgbIu8"},
{"X-FusionAuth-TenantId", "6b40f9d6-cfd8-4312-bff8-b082ad45e93c"}
]
]}
]
},
__module__: Tesla,
body: %{
"user" => %{
"active" => true,
"email" => "cogadmin@cogility.com",
"firstName" => "Cogility",
"fullName" => "Cogility Admin",
"id" => "06da543e-df3e-4011-b122-a9ff04326599",
"insertInstant" => 1590606624689,
"lastLoginInstant" => 1591138635342,
"lastName" => "Admin",
"memberships" => [
%{
"groupId" => "6f0a1769-21f3-4705-a653-bd66c3ff6a63",
"id" => "ff6fea80-31a3-439b-b880-def21933a01d",
"insertInstant" => 1590705735370
}
],
"mobilePhone" => "6092895176",
"passwordChangeRequired" => false,
"passwordLastUpdateInstant" => 1590606624715,
"preferredLanguages" => ["en"],
"registrations" => [
%{
"applicationId" => "f8109431-14f2-4815-9987-77fdedeff802",
"id" => "7aaad5c8-846d-4a40-b587-fa62f0e6240e",
"insertInstant" => 1590606684278,
"lastLoginInstant" => 1591138635342,
"preferredLanguages" => ["en"],
"roles" => ["admin", "user"],
"timezone" => "America/Los_Angeles",
"username" => "cogadmin",
"usernameStatus" => "ACTIVE",
"verified" => true
}
],
"tenantId" => "6b40f9d6-cfd8-4312-bff8-b082ad45e93c",
"timezone" => "America/Los_Angeles",
"twoFactorDelivery" => "None",
"twoFactorEnabled" => false,
"username" => "cogadmin",
"usernameStatus" => "ACTIVE",
"verified" => true
}
},
headers: [
{"content-type", "application/json;charset=UTF-8"},
{"content-length", "1033"},
{"date", "Thu, 04 Jun 2020 17:48:29 GMT"}
],
method: :get,
opts: [],
query: [],
status: 200,
url: "http://localhost:9011/api/user/06da543e-df3e-4011-b122-a9ff04326599"
}}
Link to this section Summary
Functions
Bulk deactivate or delete users based on their user IDs.
Change a user's password with a change password ID. This usually occurs after an email has been sent to the user and they clicked on a link to reset their password.
Change a user's password using their identity (loginID and password). Using a loginId instead of the changePasswordId bypasses the email verification and allows a password to be changed directly without first calling the forgot_password method.
Create a new user. You must specify either the email or the username or both for the User. Either of these values may be used to uniquely identify the User and may be used to authenticate the User.
Create a new user with the specified unique ID. You must specify either the email or the username or both for the User. Either of these values may be used to uniquely identify the User and may be used to authenticate the User.
Deactivate or delete a user by the user's ID. Soft deleted Users are marked as inactive but not deleted from FusionAuth.
Start forgot password workflow. For example, on your login form you may have a button for Forgot your password. This would be the API you would call to initiate the request for the user. If the email configuration is complete, the user will be sent the forgot password email containing a link containing the changePasswordId. The provided link should take the user to a form that allows them to change their password. This form should contain a hidden field for the changePasswordId generated by this API.
Get recent logins for a specific user or all users. If no userId is specified, recent logins for all users in the system will be returned.
Get a user by the user’s email.
Get a user by the user’s ID.
Get a user by the user’s login ID.
Get a user by the user’s username.
Bulk import multiple users.
Reactivate an inactive user by the user's ID.
Resend verification email.
Search for users.
Update a user.
Verify a user's email.
Link to this section Types
Specs
Specs
Link to this section Functions
Specs
bulk_delete_users(FusionAuth.client(), [String.t()], [Keyword.t()]) :: FusionAuth.result()
Bulk deactivate or delete users based on their user IDs.
Parameters (query)
dryRun :: boolean() :: Optional :: Defaults to false
To preview the user Ids to be deleted by the request without applying the requested action set this value to
true
.hardDelete :: boolean() :: Optional :: Defaults to false
To Permanently delete a user from FusionAuth set this value to
true
. Once a user has been permanently deleted, the action cannot be undone. When this value is set tofalse
the user is marked as inactive and the user will be unable log into FusionAuth. This action may be undone by reactivating the user.query :: String.t() :: Optional
The raw JSON Elasticsearch query that is used to search for Users. The
userId
,query
, andqueryString
parameters are mutually exclusive, they are listed here in order of precedence. It is necessary to use thequery
parameter when querying against registrations in order to achieve expected results, as this field is defined as a nested datatype in the Elasticsearch mapping.queryString :: String.t() :: Optional
The Elasticsearch query string that is used to search for Users to be deleted. The userId, query, and queryString parameters are mutually exclusive, they are listed here in order of precedence.
userId :: String.t() :: Optional
For more information visit the FusionAuth API Documentation for Bulk Delete Users.
Specs
change_password(FusionAuth.client(), String.t(), map()) :: FusionAuth.result()
Change a user's password with a change password ID. This usually occurs after an email has been sent to the user and they clicked on a link to reset their password.
For more information visit the FusionAuth API Documentation for Change a User's Password.
Specs
change_password_by_identity(FusionAuth.client(), map()) :: FusionAuth.result()
Change a user's password using their identity (loginID and password). Using a loginId instead of the changePasswordId bypasses the email verification and allows a password to be changed directly without first calling the forgot_password method.
For more information visit the FusionAuth API Documentation for Change a User's Password.
Specs
create_user(FusionAuth.client(), map()) :: FusionAuth.result()
Create a new user. You must specify either the email or the username or both for the User. Either of these values may be used to uniquely identify the User and may be used to authenticate the User.
For more information visit the FusionAuth API Documentation for Create a User.
Specs
create_user_with_id(FusionAuth.client(), map(), binary()) :: FusionAuth.result()
Create a new user with the specified unique ID. You must specify either the email or the username or both for the User. Either of these values may be used to uniquely identify the User and may be used to authenticate the User.
For more information visit the FusionAuth API Documentation for Create a User.
Specs
delete_user(FusionAuth.client(), String.t(), [{:key, boolean()}]) :: FusionAuth.result()
Deactivate or delete a user by the user's ID. Soft deleted Users are marked as inactive but not deleted from FusionAuth.
Parameters
- hardDelete :: boolean() :: Optional :: Defaults to false
To Permanently delete a user from FusionAuth set this value to true
. Once a user has been permanently deleted, the action cannot be undone. When this value is set to false
the user is marked as inactive and the user will be unable log into FusionAuth. This action may be undone by reactivating the user.
For more information visit the FusionAuth API Documentation for Delete a User.
Specs
forgot_password(FusionAuth.client(), String.t()) :: FusionAuth.result()
Start forgot password workflow. For example, on your login form you may have a button for Forgot your password. This would be the API you would call to initiate the request for the user. If the email configuration is complete, the user will be sent the forgot password email containing a link containing the changePasswordId. The provided link should take the user to a form that allows them to change their password. This form should contain a hidden field for the changePasswordId generated by this API.
The login identifier can be either the email or the username. The username is not case sensitive.
For more information visit the FusionAuth API Documentation for Start Forgot Password Workflow.
Specs
get_recent_logins(FusionAuth.client(), [{:key, integer() | String.t()}]) :: FusionAuth.result()
Get recent logins for a specific user or all users. If no userId is specified, recent logins for all users in the system will be returned.
Parameters
limit :: integer() :: Optional :: Defaults to 10
This parameter indicates the maximum amount of logins to return for a single request.
offset :: integer() :: Optional :: Default to 0
This parameter provides the offset into the result set. Generally speaking if you wish to paginate the results, you will increment this parameter on subsequent API request by the size of the
limit
parameter.userId :: String.t() :: Optional This parameter will narrow the results to only logins for a particular user. When this parameter is omitted, the most recent logins for all of FusionAuth will be returned.
For more information visit the FusionAuth API Documentation for Retrieve Recent Logins.
Specs
get_user_by_email(FusionAuth.client(), String.t()) :: FusionAuth.result()
Get a user by the user’s email.
For more information visit the FusionAuth API Documentation for Retrieve a User.
Specs
get_user_by_id(FusionAuth.client(), String.t()) :: FusionAuth.result()
Get a user by the user’s ID.
For more information visit the FusionAuth API Documentation for Retrieve a User.
Specs
get_user_by_login_id(FusionAuth.client(), String.t()) :: FusionAuth.result()
Get a user by the user’s login ID.
For more information visit the FusionAuth API Documentation for Retrieve a User.
Specs
get_user_by_username(FusionAuth.client(), String.t()) :: FusionAuth.result()
Get a user by the user’s username.
For more information visit the FusionAuth API Documentation for Retrieve a User.
Specs
import_users(FusionAuth.client(), list()) :: FusionAuth.result()
Bulk import multiple users.
For more information visit the FusionAuth API Documentation for Import Users.
Specs
reactivate_user(FusionAuth.client(), String.t()) :: FusionAuth.result()
Reactivate an inactive user by the user's ID.
For more information visit the FusionAuth API Documentation for Reactivate a User.
Specs
resend_verification_email(FusionAuth.client(), String.t()) :: FusionAuth.result()
Resend verification email.
For more information visit the FusionAuth API Documentation for Resend Verification Email.
Specs
search_users(FusionAuth.client(), search_criteria()) :: FusionAuth.result()
Search for users.
For more information visit the FusionAuth API Documentation for Search for Users.
Specs
update_user(FusionAuth.client(), String.t(), map()) :: FusionAuth.result()
Update a user.
For more information visit the FusionAuth API Documentation for Update a User.
Specs
verify_user_email(FusionAuth.client(), String.t()) :: FusionAuth.result()
Verify a user's email.
For more information visit the FusionAuth API Documentation for Verify a User's Email.