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

Add user session management API calls #588

Merged
merged 4 commits into from
May 24, 2024
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
6 changes: 1 addition & 5 deletions .github/workflows/matrix.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
{
"include": [
{ "ruby": "3.0" },
{ "ruby": "3.1" },
{ "ruby": "3.2" }
]
"include": [{ "ruby": "3.1" }, { "ruby": "3.2" }, { "ruby": "3.3" }]
}
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,5 @@ jobs:
run: bundle exec rake test

- name: Upload coverage
if: matrix.ruby == '3.2'
if: matrix.ruby == '3.2' || matrix.ruby == '3.3'
uses: codecov/codecov-action@4fe8c5f003fae66aa5ebb77cfd3e7bfbbda0b6b0 # pin@3.1.5
116 changes: 57 additions & 59 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@ PATH
GEM
remote: https://rubygems.org/
specs:
actionpack (7.1.2)
actionview (= 7.1.2)
activesupport (= 7.1.2)
actionpack (7.1.3.3)
actionview (= 7.1.3.3)
activesupport (= 7.1.3.3)
nokogiri (>= 1.8.5)
racc
rack (>= 2.2.4)
rack-session (>= 1.0.1)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
actionview (7.1.2)
activesupport (= 7.1.2)
actionview (7.1.3.3)
activesupport (= 7.1.3.3)
builder (~> 3.1)
erubi (~> 1.11)
rails-dom-testing (~> 2.2)
rails-html-sanitizer (~> 1.6)
activesupport (7.1.2)
activesupport (7.1.3.3)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
Expand All @@ -41,31 +41,29 @@ GEM
public_suffix (>= 2.0.2, < 6.0)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.5)
bigdecimal (3.1.8)
builder (3.2.4)
coderay (1.1.3)
concurrent-ruby (1.2.2)
concurrent-ruby (1.2.3)
connection_pool (2.4.1)
coveralls (0.7.1)
multi_json (~> 1.3)
rest-client
simplecov (>= 0.7)
term-ansicolor
thor
crack (0.4.6)
crack (1.0.0)
bigdecimal
rexml
crass (1.0.6)
diff-lcs (1.5.1)
docile (1.4.0)
domain_name (0.5.20190701)
unf (>= 0.0.5, < 1.0.0)
domain_name (0.6.20240107)
dotenv (2.8.1)
dotenv-rails (2.8.1)
dotenv (= 2.8.1)
railties (>= 3.2)
drb (2.2.0)
ruby2_keywords
drb (2.2.1)
erubi (1.12.0)
faker (2.23.0)
i18n (>= 1.8.11, < 2)
Expand All @@ -92,44 +90,45 @@ GEM
http-accept (1.7.0)
http-cookie (1.0.5)
domain_name (~> 0.5)
i18n (1.14.1)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
io-console (0.7.2)
irb (1.11.2)
rdoc
irb (1.13.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
json (2.7.1)
jwt (2.7.1)
json (2.7.2)
jwt (2.8.1)
base64
language_server-protocol (3.17.0.3)
listen (3.8.0)
listen (3.9.0)
rb-fsevent (~> 0.10, >= 0.10.3)
rb-inotify (~> 0.9, >= 0.9.10)
loofah (2.21.4)
loofah (2.22.0)
crass (~> 1.0.2)
nokogiri (>= 1.12.0)
lumberjack (1.2.9)
method_source (1.0.0)
mime-types (3.5.1)
lumberjack (1.2.10)
method_source (1.1.0)
mime-types (3.5.2)
mime-types-data (~> 3.2015)
mime-types-data (3.2023.1003)
minitest (5.20.0)
mime-types-data (3.2024.0507)
minitest (5.23.1)
multi_json (1.15.0)
mutex_m (0.2.0)
nenv (0.3.0)
netrc (0.11.0)
nokogiri (1.16.2-aarch64-linux)
nokogiri (1.16.5-aarch64-linux)
racc (~> 1.4)
nokogiri (1.16.2-arm64-darwin)
nokogiri (1.16.5-arm64-darwin)
racc (~> 1.4)
nokogiri (1.16.2-x86_64-darwin)
nokogiri (1.16.5-x86_64-darwin)
racc (~> 1.4)
nokogiri (1.16.2-x86_64-linux)
nokogiri (1.16.5-x86_64-linux)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
parallel (1.24.0)
parser (3.3.0.5)
parser (3.3.1.0)
ast (~> 2.4.1)
racc
pp (0.5.0)
Expand All @@ -140,9 +139,9 @@ GEM
method_source (~> 1.0)
psych (5.1.2)
stringio
public_suffix (5.0.4)
racc (1.7.3)
rack (3.0.8)
public_suffix (5.0.5)
racc (1.8.0)
rack (3.0.11)
rack-session (2.0.0)
rack (>= 3.0.0)
rack-test (2.1.0)
Expand All @@ -157,31 +156,32 @@ GEM
rails-html-sanitizer (1.6.0)
loofah (~> 2.21)
nokogiri (~> 1.14)
railties (7.1.2)
actionpack (= 7.1.2)
activesupport (= 7.1.2)
railties (7.1.3.3)
actionpack (= 7.1.3.3)
activesupport (= 7.1.3.3)
irb
rackup (>= 1.0.0)
rake (>= 12.2)
thor (~> 1.0, >= 1.2.2)
zeitwerk (~> 2.6)
rainbow (3.1.1)
rake (13.1.0)
rake (13.2.1)
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
rb-inotify (0.11.1)
ffi (~> 1.0)
rdoc (6.6.2)
rdoc (6.7.0)
psych (>= 4.0.0)
regexp_parser (2.9.0)
reline (0.4.2)
regexp_parser (2.9.2)
reline (0.5.7)
io-console (~> 0.5)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
retryable (3.0.5)
rexml (3.2.6)
rexml (3.2.8)
strscan (>= 3.0.9)
rspec (3.13.0)
rspec-core (~> 3.13.0)
rspec-expectations (~> 3.13.0)
Expand All @@ -191,30 +191,29 @@ GEM
rspec-expectations (3.13.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-mocks (3.13.0)
rspec-mocks (3.13.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.13.0)
rspec-support (3.13.0)
rubocop (1.60.2)
rspec-support (3.13.1)
rubocop (1.64.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.30.0)
parser (>= 3.2.1.0)
rubocop-rails (2.23.1)
rubocop-ast (1.31.3)
parser (>= 3.3.1.0)
rubocop-rails (2.25.0)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop-ast (>= 1.30.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
ruby-progressbar (1.13.0)
ruby2_keywords (0.0.5)
shellany (0.0.1)
simplecov (0.22.0)
docile (~> 1.1)
Expand All @@ -226,28 +225,27 @@ GEM
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
stringio (3.1.0)
strscan (3.1.0)
sync (0.5.0)
term-ansicolor (1.7.1)
term-ansicolor (1.8.0)
tins (~> 1.0)
terminal-notifier-guard (1.7.0)
thor (1.3.0)
thor (1.3.1)
timecop (0.9.8)
tins (1.32.1)
tins (1.33.0)
bigdecimal
sync
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unf (0.1.4)
unf_ext
unf_ext (0.0.9)
unicode-display_width (2.5.0)
vcr (6.2.0)
webmock (3.20.0)
webmock (3.23.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
webrick (1.8.1)
zache (0.13.1)
zeitwerk (2.6.12)
zeitwerk (2.6.14)

PLATFORMS
aarch64-linux
Expand Down
20 changes: 20 additions & 0 deletions lib/auth0/api/v2/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,26 @@ def delete_user_authentication_method(user_id, authentication_method_id)
delete "#{users_path}/#{user_id}/authentication-methods/#{authentication_method_id}"
end

# Delete all sessions for a user.
#
# @param user_id [string] The user ID
# @see https://auth0.com/docs/api/management/v2/users/delete-sessions-for-user
def delete_user_sessions(user_id)
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?

delete "#{users_path}/#{user_id}/sessions"
end

# Retrieve details for a user's sessions.
#
# @param user_id [string] The user ID
# @see https://auth0.com/docs/api/management/v2/users/get-sessions-for-user
def user_sessions(user_id)
raise Auth0::MissingUserId, 'Must supply a valid user_id' if user_id.to_s.empty?

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

private

# Users API path
Expand Down
45 changes: 45 additions & 0 deletions spec/lib/auth0/api/v2/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -801,4 +801,49 @@
end.to_not raise_error
end
end

context '.delete_user_sessions' do
it 'is expected to respond to delete_user_sessions' do
expect(@instance).to respond_to(:delete_user_sessions)
end

it 'is expected to raise an exception for a missing user ID' do
expect { @instance.delete_user_sessions(nil) }.to raise_exception(Auth0::MissingUserId)
end

it 'is expected to call the endpoint' do
expect(@instance).to receive(:delete).with(
'/api/v2/users/USER_ID/sessions'
)

expect do
@instance.delete_user_sessions 'USER_ID'
end.to_not raise_error
end
end

context '.user_sessions' do
it 'is expected to respond to user_sessions' do
expect(@instance).to respond_to :user_authentication_method
end

it 'is expected to respond to user_sessions' do
expect(@instance).to respond_to :user_sessions
end

it 'is expected to raise an exception for a missing user ID' do
expect { @instance.user_sessions(nil) }.to raise_exception(Auth0::MissingUserId)
end

it 'is expected to GET a user authentication method' do
expect(@instance).to receive(:get).with(
'/api/v2/users/USER_ID/sessions'
)

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

end
end
end