Module: Auth0::Api::V2::Organizations

Includes:
Mixins::Validation
Included in:
Auth0::Api::V2
Defined in:
lib/auth0/api/v2/organizations.rb

Overview

Methods to use the organizations endpoints

Instance Method Summary collapse

Methods included from Mixins::Validation

#validate_permissions_array, #validate_strings_array

Instance Method Details

#create_organization(options = {}) ⇒ json

Create a new organization.

Parameters:

Returns:

  • (json)

    Returns the created organization.

See Also:



35
36
37
# File 'lib/auth0/api/v2/organizations.rb', line 35

def create_organization(options = {})
  post(organizations_path, options)
end

#create_organizations_client_grant(organization_id, grant_id) ⇒ Object

Associate a client grant with an organization

Parameters:

  • organization_id (string)

    The Organization ID

  • grant_id (string)

    The Client Grant ID you want to associate to the Organization.

Raises:



357
358
359
360
361
362
363
364
365
366
# File 'lib/auth0/api/v2/organizations.rb', line 357

def create_organizations_client_grant(organization_id, grant_id)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid grant_id' if grant_id.to_s.empty?
  
  body = {}
  body[:grant_id] = grant_id

  path = "#{organizations_client_grants_path(organization_id)}"
  post(path, body)
end

#create_organizations_enabled_connection(organization_id, connection_id, assign_membership_on_login: false) ⇒ json Also known as: add_organizations_enabled_connection

Add an enabled connection for an Organization

Parameters:

  • organization_id (string)

    The Organization ID

  • connection_id (string)

    The Organization ID

  • assign_membership_on_login (boolean) (defaults to: false)

    flag to allow assign membership on login

Returns:

  • (json)

    Returns the connection for the given organization

Raises:

See Also:



138
139
140
141
142
143
144
145
146
147
148
# File 'lib/auth0/api/v2/organizations.rb', line 138

def create_organizations_enabled_connection(organization_id, connection_id, assign_membership_on_login: false)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
  path = "#{organizations_enabled_connections_path(organization_id)}"
  
  body = {}
  body[:assign_membership_on_login] = 
  body[:connection_id] = connection_id

  post(path, body)
end

#create_organizations_invite(organization_id, options = {}) ⇒ json Also known as: add_organizations_invite

Create an invitation in an organization

Parameters:

Returns:

  • (json)

    Returns the invitation for the given organization

Raises:

See Also:



194
195
196
197
198
199
# File 'lib/auth0/api/v2/organizations.rb', line 194

def create_organizations_invite(organization_id, options = {})
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  path = "#{organizations_invitations_path(organization_id)}"
  
  post(path, options)
end

#create_organizations_member_roles(organization_id, user_id, roles = []) ⇒ json Also known as: add_organizations_member_roles

Assign roles to a member in an organization

Parameters:

  • organization_id (string)

    The Organization ID

  • user_id (string)

    The User ID

  • roles (array) (defaults to: [])

    Array of role IDs.

Returns:

  • (json)

    Returns the invitation for the given organization

Raises:

See Also:



302
303
304
305
306
307
308
309
310
311
312
# File 'lib/auth0/api/v2/organizations.rb', line 302

def create_organizations_member_roles(organization_id, user_id, roles = [])
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid user id' if user_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply an array of role ids' if roles.empty?
  path = "#{organizations_member_roles_path(organization_id, user_id)}"
  
  body = {}
  body[:roles] = roles

  post(path, body)
end

#create_organizations_members(organization_id, members = []) ⇒ json Also known as: add_organizations_members

Add members in an organization

Parameters:

  • organization_id (string)

    The Organization ID

  • members (array) (defaults to: [])

    Array of user IDs.

Returns:

  • (json)

    Returns the invitation for the given organization

Raises:

See Also:



252
253
254
255
256
257
258
259
260
261
# File 'lib/auth0/api/v2/organizations.rb', line 252

def create_organizations_members(organization_id, members = [])
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply an array of member ids' if members.empty?
  path = "#{organizations_members_path(organization_id)}"
  
  body = {}
  body[:members] = members

  post(path, body)
end

#delete_organization(organization_id) ⇒ Object

Deletes a single organization given its id

Parameters:

  • organization_id (string)

    The Organization ID

Raises:

See Also:



65
66
67
68
69
# File 'lib/auth0/api/v2/organizations.rb', line 65

def delete_organization(organization_id)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  path = "#{organizations_path}/#{organization_id}"
  delete(path)
end

#delete_organizations_client_grant(organization_id, grant_id) ⇒ Object

Remove a client grant from an organization

Parameters:

  • organization_id (string)

    The Organization ID

  • grant_id (string)

    The Client Grant ID you want to remove from the Organization.

Raises:



371
372
373
374
375
376
377
# File 'lib/auth0/api/v2/organizations.rb', line 371

def delete_organizations_client_grant(organization_id, grant_id)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid grant_id' if grant_id.to_s.empty?

  path = "#{organizations_path}/#{organization_id}/client-grants/#{grant_id}"
  delete(path)
end

#delete_organizations_enabled_connection(organization_id, connection_id) ⇒ Object Also known as: remove_organizations_enabled_connection

Remove an enabled connection from an Organization

Parameters:

  • organization_id (string)

    The Organization ID

  • connection_id (string)

    The Connection id

Raises:

See Also:



155
156
157
158
159
160
# File 'lib/auth0/api/v2/organizations.rb', line 155

def delete_organizations_enabled_connection(organization_id, connection_id)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
  path = "#{organizations_enabled_connections_path(organization_id)}/#{connection_id}"
  delete(path)
end

#delete_organizations_invite(organization_id, invitation_id) ⇒ Object Also known as: remove_organizations_invite

Delete an invitation to organization

Parameters:

  • organization_id (string)

    The Organization ID

  • invitation_id (string)

    The Invitation id

Raises:

See Also:



206
207
208
209
210
211
# File 'lib/auth0/api/v2/organizations.rb', line 206

def delete_organizations_invite(organization_id, invitation_id)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid invitation id' if invitation_id.to_s.empty?
  path = "#{organizations_invitations_path(organization_id)}/#{invitation_id}"
  delete(path)
end

#delete_organizations_member_roles(organization_id, user_id, roles = []) ⇒ Object Also known as: remove_organizations_member_roles

Parameters:

  • organization_id (string)

    The Organization ID

  • user_id (string)

    The User ID

  • roles (array) (defaults to: [])

    Array of role IDs.

Raises:



320
321
322
323
324
325
326
327
328
329
330
# File 'lib/auth0/api/v2/organizations.rb', line 320

def delete_organizations_member_roles(organization_id, user_id, roles = [])
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid user id' if user_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply an array of role ids' if roles.empty?
  path = "#{organizations_member_roles_path(organization_id, user_id)}"
            
  body = {}
  body[:roles] = roles

  delete_with_body(path, body)
end

#delete_organizations_members(organization_id, members = []) ⇒ Object Also known as: remove_organizations_members

Remove members from an organization

Parameters:

  • organization_id (string)

    The Organization ID

  • members (array) (defaults to: [])

    Array of user IDs.

Raises:

See Also:



268
269
270
271
272
273
274
275
276
277
# File 'lib/auth0/api/v2/organizations.rb', line 268

def delete_organizations_members(organization_id, members = [])
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply an array of member ids' if members.empty?
  path = "#{organizations_members_path(organization_id)}"

  body = {}
  body[:members] = members

  delete_with_body(path, body)
end

#get_organizations_client_grants(organization_id, options = {}) ⇒ Object

Get client grants associated to an organization

Parameters:

  • organization_id (string)

    The Organization ID

  • options (hash) (defaults to: {})

    The Hash options used to define the paging of results

    • :client_id [string] The client_id of the client grant to retrieve.

    • :audience [string] The audience of the client grant to retrieve.

    • :per_page [integer] The amount of entries per page. Default: 50. Max value: 100.

    • :page [integer] The page number. Zero based.

    • :include_totals [boolean] True to include query summary in the result, false or nil otherwise.

Raises:



341
342
343
344
345
346
347
348
349
350
351
352
# File 'lib/auth0/api/v2/organizations.rb', line 341

def get_organizations_client_grants(organization_id, options= {})
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  request_params = {
    client_id:      options.fetch(:client_id, nil),
    audience:       options.fetch(:audience, nil),
    per_page:       options.fetch(:per_page, nil),
    page:           options.fetch(:page, nil),
    include_totals: options.fetch(:include_totals, nil)
  }
  path = "#{organizations_client_grants_path(organization_id)}"
  get(path, request_params)
end

#get_organizations_enabled_connection(organization_id, connection_id) ⇒ json

Get enabled connection by id in an Organization

Parameters:

  • organization_id (string)

    The Organization ID

  • connection_id (string)

    The Connection id

Returns:

  • (json)

    Returns the connection for the given organization

Raises:

See Also:



104
105
106
107
108
109
# File 'lib/auth0/api/v2/organizations.rb', line 104

def get_organizations_enabled_connection(organization_id, connection_id)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
  path = "#{organizations_enabled_connections_path(organization_id)}/#{connection_id}"
  get(path)
end

#get_organizations_enabled_connections(organization_id) ⇒ json

Get enabled connections in an Organization

Parameters:

  • organization_id (string)

    The Organization ID

Returns:

  • (json)

    Returns the enabled connections for the given organization

Raises:

See Also:



92
93
94
95
96
# File 'lib/auth0/api/v2/organizations.rb', line 92

def get_organizations_enabled_connections(organization_id)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  path = "#{organizations_enabled_connections_path(organization_id)}"
  get(path)
end

#get_organizations_invite(organization_id, invitation_id) ⇒ json

Get invite by id in an Organization

Parameters:

  • organization_id (string)

    The Organization ID

  • invitation_id (string)

    The invitation id

Returns:

  • (json)

    Returns the invitation for the given organization

Raises:

See Also:



182
183
184
185
186
187
# File 'lib/auth0/api/v2/organizations.rb', line 182

def get_organizations_invite(organization_id, invitation_id)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid invitation id' if invitation_id.to_s.empty?
  path = "#{organizations_invitations_path(organization_id)}/#{invitation_id}"
  get(path)
end

#get_organizations_invites(organization_id) ⇒ json

Get invites in an Organization

Parameters:

  • organization_id (string)

    The Organization ID

Returns:

  • (json)

    Returns the invites for the given organization

Raises:

See Also:



170
171
172
173
174
# File 'lib/auth0/api/v2/organizations.rb', line 170

def get_organizations_invites(organization_id)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  path = "#{organizations_invitations_path(organization_id)}"
  get(path)
end

#get_organizations_member_roles(organization_id, user_id) ⇒ json

Get Roles assigned to a Member in an Organization

Parameters:

  • organization_id (string)

    The Organization ID

  • user_id (string)

    The User ID

Returns:

  • (json)

    Returns the member_roles for the given organization

Raises:

See Also:



288
289
290
291
292
293
# File 'lib/auth0/api/v2/organizations.rb', line 288

def get_organizations_member_roles(organization_id, user_id)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid user id' if user_id.to_s.empty?
  path = "#{organizations_member_roles_path(organization_id, user_id)}"
  get(path)
end

#get_organizations_members(organization_id, options = {}) ⇒ json

Get Members in a Organization 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.

Parameters:

  • organization_id (string)

    The Organization ID

  • options (hash) (defaults to: {})

    The Hash options used to define the paging of rersults

    • :per_page [integer] The amount of entries per page. Default: 50. Max value: 100.

    • :page [integer] The page number. Zero based.

    • :from [string] For checkpoint pagination, the ID from which to start selection from.

    • :take [integer] For checkpoint pagination, the number of entries to retrieve. Default is 50.

    • :include_totals [boolean] True to include query summary in the result, false or nil otherwise.

    • :fields [string] A comma separated list of fields to include or exclude from the result. If fields is left blank, all fields (except roles) are returned.

    • :include_fields [boolean] True if the fields specified are to be included in the result, false otherwise.

Returns:

  • (json)

    Returns the members for the given organization

Raises:

See Also:



231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'lib/auth0/api/v2/organizations.rb', line 231

def get_organizations_members(organization_id, options = {})
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  request_params = {
    per_page:       options.fetch(:per_page, nil),
    page:           options.fetch(:page, nil),
    from:           options.fetch(:from, nil),
    take:           options.fetch(:take, nil),
    include_totals: options.fetch(:include_totals, nil),
    fields: options.fetch(:fields, nil),
    include_fields: options.fetch(:include_fields, nil)
  }
  path = "#{organizations_members_path(organization_id)}"
  get(path, request_params)
end

#organization(organization_id) ⇒ json

Get an organization by id. A token with read:organizations scope is required

Parameters:

  • organization_id (string)

    The organization_id of the user to retrieve.

Returns:

  • (json)

    Returns the organization with the given organization_id if it exists.

Raises:

See Also:



44
45
46
47
48
# File 'lib/auth0/api/v2/organizations.rb', line 44

def organization(organization_id)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  path = "#{organizations_path}/#{organization_id}"
  get(path)
end

#organization_by_name(organization_name) ⇒ json

Get an organization by name. A token with read:organizations scope is required.

Parameters:

  • organization_name (string)

    The Organization name

Returns:

  • (json)

    Returns the organization with the given organization_name if it exists.

Raises:

See Also:



55
56
57
58
59
# File 'lib/auth0/api/v2/organizations.rb', line 55

def organization_by_name(organization_name)
  raise Auth0::InvalidParameter, 'Must supply a valid organization_name' if organization_name.to_s.empty?
  path = "#{organizations_path}/name/#{organization_name}"
  get(path)
end

#organizations(options = {}) ⇒ json Also known as: get_organizations

Get all organizations.

Parameters:

  • options (hash) (defaults to: {})

    The Hash options used to define the paging of results

    • :per_page [integer] The amount of entries per page. Default: 50. Max value: 100.

    • :page [integer] The page number. Zero based.

    • :from [string] For checkpoint pagination, the ID from which to start selection from.

    • :take [integer] For checkpoint pagination, the number of entries to retrieve. Default is 50.

    • :include_totals [boolean] True to include query summary in the result, false or nil otherwise.

Returns:

  • (json)

    All Organizations

See Also:



19
20
21
22
23
24
25
26
27
28
# File 'lib/auth0/api/v2/organizations.rb', line 19

def organizations(options = {})
  request_params = {
    per_page:       options.fetch(:per_page, nil),
    page:           options.fetch(:page, nil),
    from:           options.fetch(:from, nil),
    take:           options.fetch(:take, nil),
    include_totals: options.fetch(:include_totals, nil)
  }
  get(organizations_path, request_params)
end

#patch_organization(organization_id, body) ⇒ json Also known as: update_organization

Update an existing organization.

Parameters:

  • organization_id (string)

    The Organization ID

  • body (hash)

    The optional parameters to update.

Returns:

  • (json)

    Returns the updated user.

Raises:

See Also:



77
78
79
80
81
82
# File 'lib/auth0/api/v2/organizations.rb', line 77

def patch_organization(organization_id, body)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid body' if body.to_s.empty? || body.empty?
  path = "#{organizations_path}/#{organization_id}"
  patch(path, body)
end

#patch_organizations_enabled_connection(organization_id, connection_id, assign_membership_on_login: nil) ⇒ json Also known as: update_organizations_enabled_connection

Update an eanbled connection in an Organization

Parameters:

  • organization_id (string)

    The Organization ID

  • connection_id (string)

    The Connection id

  • assign_membership_on_login (boolean) (defaults to: nil)

    flag to allow assign membership on login

Returns:

  • (json)

    Returns the connection for the given organization

Raises:

See Also:



118
119
120
121
122
123
124
125
126
127
128
# File 'lib/auth0/api/v2/organizations.rb', line 118

def patch_organizations_enabled_connection(organization_id, connection_id, assign_membership_on_login: nil)
  raise Auth0::MissingOrganizationId, 'Must supply a valid organization_id' if organization_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid connection id' if connection_id.to_s.empty?
  raise Auth0::InvalidParameter, 'Must supply a valid assign_membership_on_login value' if .nil?
  path = "#{organizations_enabled_connections_path(organization_id)}/#{connection_id}"

  body = {}
  body[:assign_membership_on_login] = 

  patch(path, body)
end