Skip to content
Open
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
15 changes: 13 additions & 2 deletions lib/auth0/api/v2/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,22 @@ def delete_user_sessions(user_id)
# Retrieve details for a user's sessions.
#
# @param user_id [string] The user ID
# @param options [hash] A hash of options for getting permissions
# * :take [Integer] Number of results per page. Defaults to 50.
# * :from [String] Optional token ID from which to start selection (exclusive).
# * :include_totals [boolean] Return results inside an object that contains the total result count (true)
# or as a direct array of results (false, default)
# @see https://auth0.com/docs/api/management/v2/users/get-sessions-for-user
def user_sessions(user_id)
def user_sessions(user_id, options = {})
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?

get "#{users_path}/#{user_id}/sessions"
request_params = {
take: options.fetch(:take, nil),
from: options.fetch(:from, nil),
include_totals: options.fetch(:include_totals, nil)
}

get "#{users_path}/#{user_id}/sessions", request_params
end

# Retrieve details for a user's refresh tokens.
Expand Down
22 changes: 20 additions & 2 deletions spec/lib/auth0/api/v2/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -837,13 +837,31 @@

it 'is expected to GET a user authentication method' do
expect(@instance).to receive(:get).with(
'/api/v2/users/USER_ID/sessions'
'/api/v2/users/USER_ID/sessions',
{
from: nil,
take: nil,
include_totals: nil
}
)

expect do
@instance.user_sessions('USER_ID')
end.not_to raise_error
end

it 'is expected to get user sessions with custom parameters' do
expect(@instance).to receive(:get).with(
'/api/v2/users/USER_ID/sessions',
{
from: 'TOKEN_ID',
take: 10,
include_totals: true
}
)
expect do
@instance.user_sessions('USER_ID', from: 'TOKEN_ID', take: 10, include_totals: true)
end.not_to raise_error
end
end

context '.user_refresh_tokens' do
Expand Down