Class: Auth0::Organizations::Members::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/auth0/organizations/members/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



10
11
12
# File 'lib/auth0/organizations/members/client.rb', line 10

def initialize(client:)
  @client = client
end

Instance Method Details

#create(request_options: {}, **params) ⇒ untyped

Set one or more existing users as members of a specific [Organization](auth0.com/docs/manage-users/organizations).

To add a user to an Organization through this action, the user must already exist in your tenant. If a user does not yet exist, you can [invite them to create an account](auth0.com/docs/manage-users/organizations/configure-organizations/invite-members), manually create them through the Auth0 Dashboard, or use the Management API.

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:

  • (untyped)

Raises:

  • (error_class)


107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/auth0/organizations/members/client.rb', line 107

def create(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  request_data = Auth0::Organizations::Members::Types::CreateOrganizationMemberRequestContent.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: "organizations/#{URI.encode_uri_component(params[:id].to_s)}/members",
    body: body,
    request_options: 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

#delete(request_options: {}, **params) ⇒ untyped

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:

  • (untyped)

Raises:

  • (error_class)


142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
# File 'lib/auth0/organizations/members/client.rb', line 142

def delete(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  request_data = Auth0::Organizations::Members::Types::DeleteOrganizationMembersRequestContent.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: "DELETE",
    path: "organizations/#{URI.encode_uri_component(params[:id].to_s)}/members",
    body: body,
    request_options: 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

#effective_rolesAuth0::EffectiveRoles::Client

Returns:

  • (Auth0::EffectiveRoles::Client)


168
169
170
# File 'lib/auth0/organizations/members/client.rb', line 168

def effective_roles
  @effective_roles ||= Auth0::Organizations::Members::EffectiveRoles::Client.new(client: @client)
end

#list(request_options: {}, **params) ⇒ Auth0::Types::ListOrganizationMembersPaginatedResponseContent

List organization members. This endpoint is subject to eventual consistency. New users may not be immediately included in the response and deleted users may not be immediately removed from it.

  • Use the ‘fields` parameter to optionally define the specific member details retrieved. If `fields` is left

blank, all fields (except roles) are returned.

  • Member roles are not sent by default. Use ‘fields=roles` to retrieve the roles assigned to each listed

member. To use this parameter, you must include the ‘read:organization_member_roles` scope in the token.

This endpoint supports two types of pagination:

  • Offset pagination

  • Checkpoint pagination

Checkpoint pagination must be used if you need to retrieve more than 1000 organization members.

**Checkpoint Pagination**

To search by checkpoint, use the following parameters: - from: Optional id from which to start selection. - take: The total amount of entries to retrieve when using the from parameter. Defaults to 50. Note: The first time you call this endpoint using Checkpoint Pagination, you should omit the ‘from` parameter. If there are more results, a `next` value will be included in the response. You can use this for subsequent API calls. When `next` is no longer included in the response, this indicates there are no more pages remaining.

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):

  • :id (String)
  • :from (String, nil)
  • :take (Integer, nil)
  • :fields (String, nil)
  • :include_fields (Boolean, nil)

Returns:



52
53
54
55
56
57
58
59
60
61
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/organizations/members/client.rb', line 52

def list(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["from"] = params[:from] if params.key?(:from)
  query_params["take"] = params.fetch(:take, 50)
  query_params["fields"] = params[:fields] if params.key?(:fields)
  query_params["include_fields"] = params[:include_fields] if params.key?(:include_fields)

  Auth0::Internal::CursorItemIterator.new(
    cursor_field: :next_,
    item_field: :members,
    initial_cursor: query_params["from"]
  ) do |next_cursor|
    query_params["from"] = next_cursor
    request = Auth0::Internal::JSON::Request.new(
      base_url: request_options[:base_url],
      method: "GET",
      path: "organizations/#{URI.encode_uri_component(params[:id].to_s)}/members",
      query: query_params,
      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)
      parsed_response = Auth0::Types::ListOrganizationMembersPaginatedResponseContent.load(response.body)
      [parsed_response, response]
    else
      error_class = Auth0::Errors::ResponseError.subclass_for_code(code)
      raise error_class.new(response.body, code: code)
    end
  end
end

#rolesAuth0::Roles::Client



173
174
175
# File 'lib/auth0/organizations/members/client.rb', line 173

def roles
  @roles ||= Auth0::Organizations::Members::Roles::Client.new(client: @client)
end