Skip to content

Commit

Permalink
API support for Users/Clear_user_sessions (Shopify#13)
Browse files Browse the repository at this point in the history
* adding support for clear_user_sessions api endpoint
  • Loading branch information
pascalcharest authored Dec 12, 2018
1 parent 7566c7c commit 3ffb4ef
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 26 deletions.
14 changes: 7 additions & 7 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ Lint/AssignmentInCondition:
Style/Documentation:
Enabled: false

Style/MultilineOperationIndentation:
Layout/MultilineOperationIndentation:
Enabled: false

Style/AlignParameters:
Layout/AlignParameters:
EnforcedStyle: with_fixed_indentation

Style/FirstParameterIndentation:
Layout/FirstParameterIndentation:
EnforcedStyle: consistent

Style/Style/TrailingCommaInArrayLiteral:
Style/TrailingCommaInArrayLiteral:
Enabled: false

Style/SignalException:
Expand All @@ -31,10 +31,10 @@ Style/SignalException:
Style/NumericLiterals:
Enabled: false

Style/CaseIndentation:
Layout/CaseIndentation:
EnforcedStyle: end

Style/IndentHash:
Layout/IndentHash:
EnforcedStyle: consistent

Style/WordArray:
Expand Down Expand Up @@ -69,7 +69,7 @@ Metrics/ParameterLists:
Metrics/PerceivedComplexity:
Enabled: false

Lint/EndAlignment:
Layout/EndAlignment:
EnforcedStyleAlignWith: variable

Style/FrozenStringLiteralComment:
Expand Down
51 changes: 33 additions & 18 deletions lib/oktakit/client/users.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Users
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Returns the created User.
# @see http://developer.okta.com/docs/api/resources/users.html#create-user
# @see https://developer.okta.com/docs/api/resources/users#create-user
# @example
# Oktakit.create_user
def create_user(options = {})
Expand All @@ -25,7 +25,7 @@ def create_user(options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Fetched User
# @see http://developer.okta.com/docs/api/resources/users.html#get-user
# @see https://developer.okta.com/docs/api/resources/users#get-user
# @example
# Oktakit.get_user('id')
def get_user(id, options = {})
Expand All @@ -40,7 +40,7 @@ def get_user(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Array<Sawyer::Resource>] Array of User
# @see http://developer.okta.com/docs/api/resources/users.html#list-users
# @see https://developer.okta.com/docs/api/resources/users#list-users
# @example
# Oktakit.list_users
def list_users(options = {})
Expand All @@ -56,7 +56,7 @@ def list_users(options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Updated User
# @see http://developer.okta.com/docs/api/resources/users.html#update-user
# @see https://developer.okta.com/docs/api/resources/users#update-user
# @example
# Oktakit.update_user('id')
def update_user(id, options = {})
Expand All @@ -72,7 +72,7 @@ def update_user(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Updated User
# @see http://developer.okta.com/docs/api/resources/users.html#update-profile
# @see https://developer.okta.com/docs/api/resources/users#update-profile
# @example
# Oktakit.update_profile('id')
def update_profile(id, options = {})
Expand All @@ -87,7 +87,7 @@ def update_profile(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Array<Sawyer::Resource>] Array of App Links
# @see http://developer.okta.com/docs/api/resources/users.html#get-assigned-app-links
# @see https://developer.okta.com/docs/api/resources/users#get-assigned-app-links
# @example
# Oktakit.get_assigned_app_links('id')
def get_assigned_app_links(id, options = {})
Expand All @@ -103,7 +103,7 @@ def get_assigned_app_links(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Array<Sawyer::Resource>] Array of Groups
# @see http://developer.okta.com/docs/api/resources/users.html#get-member-groups
# @see https://developer.okta.com/docs/api/resources/users#get-member-groups
# @example
# Oktakit.get_member_groups('id')
def get_member_groups(id, options = {})
Expand All @@ -119,7 +119,7 @@ def get_member_groups(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Returns empty object by default. If sendEmail is false, a user activation link.
# @see http://developer.okta.com/docs/api/resources/users.html#activate-user
# @see https://developer.okta.com/docs/api/resources/users#activate-user
# @example
# Oktakit.activate_user('id')
def activate_user(id, options = {})
Expand All @@ -135,7 +135,7 @@ def activate_user(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Returns an empty object.
# @see http://developer.okta.com/docs/api/resources/users.html#deactivate-user
# @see https://developer.okta.com/docs/api/resources/users#deactivate-user
# @example
# Oktakit.deactivate_user('id')
def deactivate_user(id, options = {})
Expand All @@ -151,7 +151,7 @@ def deactivate_user(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Returns an empty object.
# @see http://developer.okta.com/docs/api/resources/users.html#suspend-user
# @see https://developer.okta.com/docs/api/resources/users#suspend-user
# @example
# Oktakit.suspend_user('id')
def suspend_user(id, options = {})
Expand All @@ -167,7 +167,7 @@ def suspend_user(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Returns an empty object. Returns an empty object.
# @see http://developer.okta.com/docs/api/resources/users.html#unsuspend-user
# @see https://developer.okta.com/docs/api/resources/users#unsuspend-user
# @example
# Oktakit.unsuspend_user('id')
def unsuspend_user(id, options = {})
Expand All @@ -183,7 +183,7 @@ def unsuspend_user(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Returns an empty object
# @see http://developer.okta.com/docs/api/resources/users.html#unlock-user
# @see http://developer.okta.com/docs/api/resources/users#unlock-user
# @example
# Oktakit.unlock_user('id')
def unlock_user(id, options = {})
Expand All @@ -199,7 +199,7 @@ def unlock_user(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Returns an empty object by default. If sendEmail is false a password reset link
# @see http://developer.okta.com/docs/api/resources/users.html#reset-password
# @see https://developer.okta.com/docs/api/resources/users#reset-password
# @example
# Oktakit.reset_password('id')
def reset_password(id, options = {})
Expand All @@ -215,7 +215,7 @@ def reset_password(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Returns the user by default. If tempPassword is true, a temporary password.
# @see http://developer.okta.com/docs/api/resources/users.html#expire-password
# @see https://developer.okta.com/docs/api/resources/users#expire-password
# @example
# Oktakit.expire_password('id')
def expire_password(id, options = {})
Expand All @@ -231,7 +231,7 @@ def expire_password(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Returns an empty object by default.
# @see http://developer.okta.com/docs/api/resources/users.html#reset-factors
# @see https://developer.okta.com/docs/api/resources/users#reset-factors
# @example
# Oktakit.reset_factors('id')
def reset_factors(id, options = {})
Expand All @@ -247,7 +247,7 @@ def reset_factors(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Returns an empty object by default. If sendEmail is false a password reset link
# @see http://developer.okta.com/docs/api/resources/users.html#forgot-password
# @see https://developer.okta.com/docs/api/resources/users#forgot-password
# @example
# Oktakit.forgot_password('id')
def forgot_password(id, options = {})
Expand All @@ -263,7 +263,7 @@ def forgot_password(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Credentials of the user
# @see http://developer.okta.com/docs/api/resources/users.html#change-password
# @see https://developer.okta.com/docs/api/resources/users#change-password
# @example
# Oktakit.change_password('id')
def change_password(id, options = {})
Expand All @@ -279,12 +279,27 @@ def change_password(id, options = {})
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for request.
# @return [Hash<Sawyer::Resource>] Credentials of the user
# @see http://developer.okta.com/docs/api/resources/users.html#change-recovery-question
# @see https://developer.okta.com/docs/api/resources/users#change-recovery-question
# @example
# Oktakit.change_recovery_question('id')
def change_recovery_question(id, options = {})
post("/users/#{id}/credentials/change_recovery_question", options)
end

# Clear user sessions
#
# @params id [string] User ID
# @param options[:query] [Hash] Optional. Query params for request
# @param options[:headers] [Hash] Optional. Header params for the request.
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
# @param options [Hash] Optional. Body params for the request.
# @return 204 'No Content'
# @see https://developer.okta.com/docs/api/resources/users#user-sessions
# Oktakit.clear_user_sessions('id')
def clear_user_sessions(id, options = {})
delete("/users/#{id}/sessions", options)
end
end
end
end
64 changes: 64 additions & 0 deletions spec/cassettes/clear_user_sessions.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
http_interactions:
- request:
method: delete
uri: https://okta-test.okta.com/api/v1/users/00u6o0w6tyuPVEeZr0h7/sessions
body:
encoding: UTF-8
string: "{}"
headers:
User-Agent:
- Oktakit v0.2.0
Accept:
- application/json
Content-Type:
- application/json
Authorization:
- SSWS <<ACCESS_TOKEN>>
response:
status:
code: 204
message:
headers:
date:
- Tue, 11 Dec 2018 21:18:03 GMT
server:
- nginx
public-key-pins-report-only:
- pin-sha256="r5EfzZxQVvQpKo3AgYRaT7X2bDO/kj3ACwmxfdT2zt8="; pin-sha256="MaqlcUgk2mvY/RFSGeSwBRkI+rZ6/dxe/DuQfBT/vnQ=";
pin-sha256="72G5IEvDEWn+EThf3qjR7/bQSWaS2ZSLqolhnO6iyJI="; pin-sha256="rrV6CLCCvqnk89gWibYT0JO6fNQ8cCit7GGoiVTjCOg=";
max-age=60; report-uri="https://okta.report-uri.io/r/default/hpkp/reportOnly"
x-okta-request-id:
- XBApi-GwicbxmsV2U8B2tgAAAbc
p3p:
- CP="HONK"
x-rate-limit-limit:
- '600'
x-rate-limit-remaining:
- '597'
x-rate-limit-reset:
- '1544563086'
cache-control:
- no-cache, no-store
pragma:
- no-cache
expires:
- '0'
x-okta-backend:
- ok2-majorapp04b.aue1p.internal
x-frame-options:
- SAMEORIGIN
strict-transport-security:
- max-age=315360000
set-cookie:
- sid=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/, JSESSIONID=7487CD03E393F36BAAC9421A8F4B00DC;
Path=/; Secure; HttpOnly
connection:
- close
body:
encoding: UTF-8
string: ''
http_version:
recorded_at: Tue, 11 Dec 2018 21:18:03 GMT
recorded_with: VCR 2.9.3

2 changes: 1 addition & 1 deletion spec/client/factors_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
factorType: "sms",
provider: "OKTA",
profile: {
phoneNumber: "+1-613-456-1234"
phoneNumber: "+1-613-456-1234"
})
expect(resp.id).not_to be_nil
end
Expand Down
9 changes: 9 additions & 0 deletions spec/client/users_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,13 @@
end
end
end

describe '#clear_user_sessions' do
it 'returns 204 no content' do
VCR.use_cassette 'clear_user_sessions' do
_, status = client.clear_user_sessions(USERS_USER_ID)
expect(status).to be(204)
end
end
end
end

0 comments on commit 3ffb4ef

Please sign in to comment.