Class: Auth0::Users::Identities::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/auth0/users/identities/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



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 Unlink User Accounts.

Examples:

client.users.identities.delete(
  id: "id",
  provider: "ad",
  user_id: "user_id"
)

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (Hash)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

Returns:



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/auth0/users/identities/client.rb', line 115

def delete(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  request = Auth0::Internal::JSON::Request.new(
    base_url: request_options[: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: 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)
    (response.body.to_s.empty? ? nil : 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 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:

  • With the authenticated primary account's JWT in the Authorization header, which has the update:current_user_identities scope:

    POST /api/v2/users/PRIMARY_ACCOUNT_USER_ID/identities
    Authorization: "Bearer PRIMARY_ACCOUNT_JWT"
    {
      "link_with": "SECONDARY_ACCOUNT_JWT"
    }
    

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.

  • With a token generated by the API V2 containing the update:users scope:

    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"
    }
    

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.

Examples:

client.users.identities.link(id: "id")

Parameters:

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Options Hash (**params):

  • :id (String)

Returns:



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/auth0/users/identities/client.rb', line 62

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 = %w[id]
  body = request_data.except(*non_body_param_names)

  request = Auth0::Internal::JSON::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "users/#{URI.encode_uri_component(params[:id].to_s)}/identities",
    body: body,
    request_options: 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::Internal::Types::Utils.coerce(Internal::Types::Array[Auth0::Types::UserIdentity], (response.body.to_s.empty? ? nil : JSON.parse(response.body, symbolize_names: true)))
  else
    error_class = Auth0::Errors::ResponseError.subclass_for_code(code)
    raise error_class.new(response.body, code: code)
  end
end