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.

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, manually create them through the Auth0 Dashboard, or use the Management API.

Examples:

client.organizations.members.create(
  id: "id",
  members: ["members"]
)

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)


127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/auth0/organizations/members/client.rb', line 127

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

Examples:

client.organizations.members.delete(
  id: "id",
  members: ["members"]
)

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)


168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/auth0/organizations/members/client.rb', line 168

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)


194
195
196
# File 'lib/auth0/organizations/members/client.rb', line 194

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. Only directly assigned roles are returned. To also include group-based role assignments, use GET /api/v2/organizations/{id}/members/{user_id}/effective-roles.

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.

Examples:

client.organizations.members.list(
  id: "id",
  include_totals: true,
  from: "from",
  take: 1,
  fields: "fields",
  include_fields: true
)

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)
  • :include_totals (Boolean, nil)
  • :from (String, nil)
  • :take (Integer, nil)
  • :fields (String, nil)
  • :include_fields (Boolean, nil)

Returns:



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/auth0/organizations/members/client.rb', line 65

def list(request_options: {}, **params)
  params = Auth0::Internal::Types::Utils.normalize_keys(params)
  query_params = {}
  query_params["include_totals"] = params.fetch(:include_totals, true)
  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 = (response.body.to_s.empty? ? nil : 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



199
200
201
# File 'lib/auth0/organizations/members/client.rb', line 199

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