Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Organizations feature #264

Merged
merged 8 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,10 @@ jobs:
steps:
- checkout
- restore_cache:
keys:
- gems-v2-{{ checksum "Gemfile.lock" }}
- gems-v2-
- run: bundle check || bundle install
key: gems-v2-{{ checksum "Gemfile.lock" }}
- run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle
- save_cache:
key: gems-v2--{{ checksum "Gemfile.lock" }}
key: gems-v2-{{ checksum "Gemfile.lock" }}
paths:
- vendor/bundle
# Must define DOMAIN, CLIENT_ID, CLIENT_SECRET and MASTER_JWT env
Expand Down
2 changes: 2 additions & 0 deletions lib/auth0/api/v2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
require 'auth0/api/v2/log_streams'
require 'auth0/api/v2/resource_servers'
require 'auth0/api/v2/guardian'
require 'auth0/api/v2/organizations'

module Auth0
module Api
Expand All @@ -45,6 +46,7 @@ module V2
include Auth0::Api::V2::LogStreams
include Auth0::Api::V2::ResourceServers
include Auth0::Api::V2::Guardian
include Auth0::Api::V2::Organizations
end
end
end
4 changes: 3 additions & 1 deletion lib/auth0/api/v2/jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ def export_users(options = {})
# @param identity [hash] Used to verify secondary, federated, and passwordless-email identities.
# * :user_id [string] user_id of the identity.
# * :provider [string] provider of the identity.
# @param organization_id [string] organization id
#
# @return [json] Returns the job status and properties.
def send_verification_email(user_id, client_id = nil, identity: nil)
def send_verification_email(user_id, client_id = nil, identity: nil, organization_id: nil)
raise Auth0::InvalidParameter, 'Must specify a user id' if user_id.to_s.empty?

request_params = { user_id: user_id }
request_params[:client_id] = client_id unless client_id.nil?
request_params[:organization_id] = organization_id unless organization_id.nil?

if identity
unless identity.is_a? Hash
Expand Down
332 changes: 332 additions & 0 deletions lib/auth0/api/v2/organizations.rb

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions lib/auth0/api/v2/tickets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ module Tickets
# @param identity [hash] Used to verify secondary, federated, and passwordless-email identities.
# * :user_id [string] user_id of the identity.
# * :provider [string] provider of the identity.
# @param client_id [string] client id
# @param organization_id [string] organization id
#
# @return [json] Returns the created ticket url.
def post_email_verification(user_id, result_url: nil, ttl_sec: nil, identity: nil)
def post_email_verification(user_id, result_url: nil, ttl_sec: nil, identity: nil, client_id: nil, organization_id: nil)
if user_id.to_s.empty?
raise Auth0::InvalidParameter, 'Must supply a valid user id to post an email verification'
end
Expand All @@ -27,6 +29,8 @@ def post_email_verification(user_id, result_url: nil, ttl_sec: nil, identity: ni
result_url: result_url,
ttl_sec: ttl_sec.is_a?(Integer) ? ttl_sec : nil
}
request_params[:client_id] = client_id unless client_id.nil?
request_params[:organization_id] = organization_id unless organization_id.nil?

if identity
unless identity.is_a? Hash
Expand All @@ -53,6 +57,8 @@ def post_email_verification(user_id, result_url: nil, ttl_sec: nil, identity: ni
# @param includeEmailInRedirect [boolean] Whether or not we include the email as part of the returnUrl
# in the reset_email
# @param new_password [string] The password to be set for the user once the ticket is used.
# @param client_id [string] client id
# @param organization_id [string] organization id
#
# @return [json] Returns the created ticket url.
def post_password_change(
Expand All @@ -63,7 +69,10 @@ def post_password_change(
ttl_sec: nil,
mark_email_as_verified: nil,
includeEmailInRedirect: nil,
new_password: nil)
new_password: nil,
client_id: nil,
organization_id: nil
)

booleans = [true, false]
path = "#{tickets_path}/password-change"
Expand All @@ -77,6 +86,9 @@ def post_password_change(
includeEmailInRedirect: booleans.include?(includeEmailInRedirect) ? includeEmailInRedirect : nil,
new_password: new_password
}
request_params[:client_id] = client_id unless client_id.nil?
request_params[:organization_id] = organization_id unless organization_id.nil?

post(path, request_params)
end

Expand Down
12 changes: 12 additions & 0 deletions lib/auth0/api/v2/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,18 @@ def invalidate_browsers(user_id)
post "#{users_path}/#{user_id}/multifactor/actions/invalidate-remember-browser"
end


# Get a list of organizations for a user.
#
# @param user_id [string] The user_id of the permissions to get.
#
# @return [json] Returns organizations for the given user_id.
def get_user_organizations(user_id)
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?

get "#{users_path}/#{user_id}/organizations"
end

private

# Users API path
Expand Down
2 changes: 2 additions & 0 deletions lib/auth0/exception.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class RequestTimeout < Auth0::Exception; end
class MissingUserId < Auth0::Exception; end
# exception for unset client_id
class MissingClientId < Auth0::Exception; end
# exception for unset organization_id
class MissingOrganizationId < Auth0::Exception; end
# exception for an unset parameter
class MissingParameter < Auth0::Exception; end
# Api v2 access denied
Expand Down
11 changes: 11 additions & 0 deletions spec/lib/auth0/api/v2/jobs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,17 @@
)
end

it 'expect client to accept organization_id' do
expect(@instance).to receive(:post).with('/api/v2/jobs/verification-email',
user_id: 'user_id',
organization_id: 'org_id'
)

expect {
@instance.send_verification_email('user_id', organization_id: 'org_id')
}.not_to raise_error
end

it 'should raise an error if the user_id is empty' do
expect do
@instance.send_verification_email('')
Expand Down
Loading