Class: Auth0::Users::Identities::Client
- Inherits:
-
Object
- Object
- Auth0::Users::Identities::Client
- Defined in:
- lib/auth0/users/identities/client.rb
Instance Method Summary collapse
-
#delete(request_options: {}, **params) ⇒ Array[Auth0::Types::DeleteUserIdentityResponseContentItem]
Unlink a specific secondary account from a target user.
- #initialize(client:) ⇒ void constructor
-
#link(request_options: {}, **params) ⇒ Array[Auth0::Types::UserIdentity]
Link two user accounts together forming a primary and secondary relationship.
Constructor Details
#initialize(client:) ⇒ void
10 11 12 |
# File 'lib/auth0/users/identities/client.rb', line 10 def initialize(client:) @client = client end |
Instance Method Details
#delete(request_options: {}, **params) ⇒ Array[Auth0::Types::DeleteUserIdentityResponseContentItem]
Unlink a specific secondary account from a target user. This action requires the ID of both the target user and the secondary account.
Unlinking the secondary account removes it from the identities array of the target user and creates a new standalone profile for the secondary account. To learn more, review <a href=“auth0.com/docs/manage-users/user-accounts/user-account-linking/unlink-user-accounts”>Unlink User Accounts</a>.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/auth0/users/identities/client.rb', line 103 def delete(request_options: {}, **params) params = Auth0::Internal::Types::Utils.normalize_keys(params) request = Auth0::Internal::JSON::Request.new( base_url: [:base_url], method: "DELETE", path: "users/#{URI.encode_uri_component(params[:id].to_s)}/identities/#{URI.encode_uri_component(params[:provider].to_s)}/#{URI.encode_uri_component(params[:user_id].to_s)}", request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Auth0::Errors::TimeoutError end code = response.code.to_i if code.between?(200, 299) Auth0::Types::DeleteUserIdentityResponseContent.load(response.body) else error_class = Auth0::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end end |
#link(request_options: {}, **params) ⇒ Array[Auth0::Types::UserIdentity]
Link two user accounts together forming a primary and secondary relationship. On successful linking, the endpoint returns the new array of the primary account identities.
Note: There are two ways of invoking the endpoint:
<ul> <li>With the authenticated primary account’s JWT in the Authorization header, which has the update:current_user_identities scope:
<pre>
POST /api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities
Authorization: "Bearer PRIMARY_ACCOUNT_JWT"
{
"link_with": "SECONDARY_ACCOUNT_JWT"
}
</pre>
In this case, only the link_with param is required in the body, which also contains the JWT obtained upon the secondary account’s authentication.
</li>
<li>With a token generated by the API V2 containing the <code>update:users</code> scope:
<pre>
POST /api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities
Authorization: "Bearer YOUR_API_V2_TOKEN"
{
"provider": "SECONDARY_ACCOUNT_PROVIDER",
"connection_id": "SECONDARY_ACCOUNT_CONNECTION_ID(OPTIONAL)",
"user_id": "SECONDARY_ACCOUNT_USER_ID"
}
</pre>
In this case you need to send provider and user_id in the body. Optionally you can also send the connection_id param which is suitable for identifying a particular database connection for the ‘auth0’ provider.
</li>
</ul>
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/auth0/users/identities/client.rb', line 58 def link(request_options: {}, **params) params = Auth0::Internal::Types::Utils.normalize_keys(params) request_data = Auth0::Users::Identities::Types::LinkUserIdentityRequestContent.new(params).to_h non_body_param_names = ["id"] body = request_data.except(*non_body_param_names) request = Auth0::Internal::JSON::Request.new( base_url: [:base_url], method: "POST", path: "users/#{URI.encode_uri_component(params[:id].to_s)}/identities", body: body, request_options: ) begin response = @client.send(request) rescue Net::HTTPRequestTimeout raise Auth0::Errors::TimeoutError end code = response.code.to_i return if code.between?(200, 299) error_class = Auth0::Errors::ResponseError.subclass_for_code(code) raise error_class.new(response.body, code: code) end |