diff --git a/lib/auth0/api/v2/users.rb b/lib/auth0/api/v2/users.rb index 71b6604d..d17016e5 100644 --- a/lib/auth0/api/v2/users.rb +++ b/lib/auth0/api/v2/users.rb @@ -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. diff --git a/spec/lib/auth0/api/v2/users_spec.rb b/spec/lib/auth0/api/v2/users_spec.rb index 4ed0f0e3..936bdfc7 100644 --- a/spec/lib/auth0/api/v2/users_spec.rb +++ b/spec/lib/auth0/api/v2/users_spec.rb @@ -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