Skip to content

Commit 3ffb4ef

Browse files
API support for Users/Clear_user_sessions (#13)
* adding support for clear_user_sessions api endpoint
1 parent 7566c7c commit 3ffb4ef

File tree

5 files changed

+114
-26
lines changed

5 files changed

+114
-26
lines changed

.rubocop.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ Lint/AssignmentInCondition:
1313
Style/Documentation:
1414
Enabled: false
1515

16-
Style/MultilineOperationIndentation:
16+
Layout/MultilineOperationIndentation:
1717
Enabled: false
1818

19-
Style/AlignParameters:
19+
Layout/AlignParameters:
2020
EnforcedStyle: with_fixed_indentation
2121

22-
Style/FirstParameterIndentation:
22+
Layout/FirstParameterIndentation:
2323
EnforcedStyle: consistent
2424

25-
Style/Style/TrailingCommaInArrayLiteral:
25+
Style/TrailingCommaInArrayLiteral:
2626
Enabled: false
2727

2828
Style/SignalException:
@@ -31,10 +31,10 @@ Style/SignalException:
3131
Style/NumericLiterals:
3232
Enabled: false
3333

34-
Style/CaseIndentation:
34+
Layout/CaseIndentation:
3535
EnforcedStyle: end
3636

37-
Style/IndentHash:
37+
Layout/IndentHash:
3838
EnforcedStyle: consistent
3939

4040
Style/WordArray:
@@ -69,7 +69,7 @@ Metrics/ParameterLists:
6969
Metrics/PerceivedComplexity:
7070
Enabled: false
7171

72-
Lint/EndAlignment:
72+
Layout/EndAlignment:
7373
EnforcedStyleAlignWith: variable
7474

7575
Style/FrozenStringLiteralComment:

lib/oktakit/client/users.rb

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module Users
99
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
1010
# @param options [Hash] Optional. Body params for request.
1111
# @return [Hash<Sawyer::Resource>] Returns the created User.
12-
# @see http://developer.okta.com/docs/api/resources/users.html#create-user
12+
# @see https://developer.okta.com/docs/api/resources/users#create-user
1313
# @example
1414
# Oktakit.create_user
1515
def create_user(options = {})
@@ -25,7 +25,7 @@ def create_user(options = {})
2525
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
2626
# @param options [Hash] Optional. Body params for request.
2727
# @return [Hash<Sawyer::Resource>] Fetched User
28-
# @see http://developer.okta.com/docs/api/resources/users.html#get-user
28+
# @see https://developer.okta.com/docs/api/resources/users#get-user
2929
# @example
3030
# Oktakit.get_user('id')
3131
def get_user(id, options = {})
@@ -40,7 +40,7 @@ def get_user(id, options = {})
4040
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
4141
# @param options [Hash] Optional. Body params for request.
4242
# @return [Array<Sawyer::Resource>] Array of User
43-
# @see http://developer.okta.com/docs/api/resources/users.html#list-users
43+
# @see https://developer.okta.com/docs/api/resources/users#list-users
4444
# @example
4545
# Oktakit.list_users
4646
def list_users(options = {})
@@ -56,7 +56,7 @@ def list_users(options = {})
5656
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
5757
# @param options [Hash] Optional. Body params for request.
5858
# @return [Hash<Sawyer::Resource>] Updated User
59-
# @see http://developer.okta.com/docs/api/resources/users.html#update-user
59+
# @see https://developer.okta.com/docs/api/resources/users#update-user
6060
# @example
6161
# Oktakit.update_user('id')
6262
def update_user(id, options = {})
@@ -72,7 +72,7 @@ def update_user(id, options = {})
7272
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
7373
# @param options [Hash] Optional. Body params for request.
7474
# @return [Hash<Sawyer::Resource>] Updated User
75-
# @see http://developer.okta.com/docs/api/resources/users.html#update-profile
75+
# @see https://developer.okta.com/docs/api/resources/users#update-profile
7676
# @example
7777
# Oktakit.update_profile('id')
7878
def update_profile(id, options = {})
@@ -87,7 +87,7 @@ def update_profile(id, options = {})
8787
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
8888
# @param options [Hash] Optional. Body params for request.
8989
# @return [Array<Sawyer::Resource>] Array of App Links
90-
# @see http://developer.okta.com/docs/api/resources/users.html#get-assigned-app-links
90+
# @see https://developer.okta.com/docs/api/resources/users#get-assigned-app-links
9191
# @example
9292
# Oktakit.get_assigned_app_links('id')
9393
def get_assigned_app_links(id, options = {})
@@ -103,7 +103,7 @@ def get_assigned_app_links(id, options = {})
103103
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
104104
# @param options [Hash] Optional. Body params for request.
105105
# @return [Array<Sawyer::Resource>] Array of Groups
106-
# @see http://developer.okta.com/docs/api/resources/users.html#get-member-groups
106+
# @see https://developer.okta.com/docs/api/resources/users#get-member-groups
107107
# @example
108108
# Oktakit.get_member_groups('id')
109109
def get_member_groups(id, options = {})
@@ -119,7 +119,7 @@ def get_member_groups(id, options = {})
119119
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
120120
# @param options [Hash] Optional. Body params for request.
121121
# @return [Hash<Sawyer::Resource>] Returns empty object by default. If sendEmail is false, a user activation link.
122-
# @see http://developer.okta.com/docs/api/resources/users.html#activate-user
122+
# @see https://developer.okta.com/docs/api/resources/users#activate-user
123123
# @example
124124
# Oktakit.activate_user('id')
125125
def activate_user(id, options = {})
@@ -135,7 +135,7 @@ def activate_user(id, options = {})
135135
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
136136
# @param options [Hash] Optional. Body params for request.
137137
# @return [Hash<Sawyer::Resource>] Returns an empty object.
138-
# @see http://developer.okta.com/docs/api/resources/users.html#deactivate-user
138+
# @see https://developer.okta.com/docs/api/resources/users#deactivate-user
139139
# @example
140140
# Oktakit.deactivate_user('id')
141141
def deactivate_user(id, options = {})
@@ -151,7 +151,7 @@ def deactivate_user(id, options = {})
151151
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
152152
# @param options [Hash] Optional. Body params for request.
153153
# @return [Hash<Sawyer::Resource>] Returns an empty object.
154-
# @see http://developer.okta.com/docs/api/resources/users.html#suspend-user
154+
# @see https://developer.okta.com/docs/api/resources/users#suspend-user
155155
# @example
156156
# Oktakit.suspend_user('id')
157157
def suspend_user(id, options = {})
@@ -167,7 +167,7 @@ def suspend_user(id, options = {})
167167
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
168168
# @param options [Hash] Optional. Body params for request.
169169
# @return [Hash<Sawyer::Resource>] Returns an empty object. Returns an empty object.
170-
# @see http://developer.okta.com/docs/api/resources/users.html#unsuspend-user
170+
# @see https://developer.okta.com/docs/api/resources/users#unsuspend-user
171171
# @example
172172
# Oktakit.unsuspend_user('id')
173173
def unsuspend_user(id, options = {})
@@ -183,7 +183,7 @@ def unsuspend_user(id, options = {})
183183
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
184184
# @param options [Hash] Optional. Body params for request.
185185
# @return [Hash<Sawyer::Resource>] Returns an empty object
186-
# @see http://developer.okta.com/docs/api/resources/users.html#unlock-user
186+
# @see http://developer.okta.com/docs/api/resources/users#unlock-user
187187
# @example
188188
# Oktakit.unlock_user('id')
189189
def unlock_user(id, options = {})
@@ -199,7 +199,7 @@ def unlock_user(id, options = {})
199199
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
200200
# @param options [Hash] Optional. Body params for request.
201201
# @return [Hash<Sawyer::Resource>] Returns an empty object by default. If sendEmail is false a password reset link
202-
# @see http://developer.okta.com/docs/api/resources/users.html#reset-password
202+
# @see https://developer.okta.com/docs/api/resources/users#reset-password
203203
# @example
204204
# Oktakit.reset_password('id')
205205
def reset_password(id, options = {})
@@ -215,7 +215,7 @@ def reset_password(id, options = {})
215215
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
216216
# @param options [Hash] Optional. Body params for request.
217217
# @return [Hash<Sawyer::Resource>] Returns the user by default. If tempPassword is true, a temporary password.
218-
# @see http://developer.okta.com/docs/api/resources/users.html#expire-password
218+
# @see https://developer.okta.com/docs/api/resources/users#expire-password
219219
# @example
220220
# Oktakit.expire_password('id')
221221
def expire_password(id, options = {})
@@ -231,7 +231,7 @@ def expire_password(id, options = {})
231231
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
232232
# @param options [Hash] Optional. Body params for request.
233233
# @return [Hash<Sawyer::Resource>] Returns an empty object by default.
234-
# @see http://developer.okta.com/docs/api/resources/users.html#reset-factors
234+
# @see https://developer.okta.com/docs/api/resources/users#reset-factors
235235
# @example
236236
# Oktakit.reset_factors('id')
237237
def reset_factors(id, options = {})
@@ -247,7 +247,7 @@ def reset_factors(id, options = {})
247247
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
248248
# @param options [Hash] Optional. Body params for request.
249249
# @return [Hash<Sawyer::Resource>] Returns an empty object by default. If sendEmail is false a password reset link
250-
# @see http://developer.okta.com/docs/api/resources/users.html#forgot-password
250+
# @see https://developer.okta.com/docs/api/resources/users#forgot-password
251251
# @example
252252
# Oktakit.forgot_password('id')
253253
def forgot_password(id, options = {})
@@ -263,7 +263,7 @@ def forgot_password(id, options = {})
263263
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
264264
# @param options [Hash] Optional. Body params for request.
265265
# @return [Hash<Sawyer::Resource>] Credentials of the user
266-
# @see http://developer.okta.com/docs/api/resources/users.html#change-password
266+
# @see https://developer.okta.com/docs/api/resources/users#change-password
267267
# @example
268268
# Oktakit.change_password('id')
269269
def change_password(id, options = {})
@@ -279,12 +279,27 @@ def change_password(id, options = {})
279279
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
280280
# @param options [Hash] Optional. Body params for request.
281281
# @return [Hash<Sawyer::Resource>] Credentials of the user
282-
# @see http://developer.okta.com/docs/api/resources/users.html#change-recovery-question
282+
# @see https://developer.okta.com/docs/api/resources/users#change-recovery-question
283283
# @example
284284
# Oktakit.change_recovery_question('id')
285285
def change_recovery_question(id, options = {})
286286
post("/users/#{id}/credentials/change_recovery_question", options)
287287
end
288+
289+
# Clear user sessions
290+
#
291+
# @params id [string] User ID
292+
# @param options[:query] [Hash] Optional. Query params for request
293+
# @param options[:headers] [Hash] Optional. Header params for the request.
294+
# @param options[:accept] [String] Optional. The content type to accept. Default application/json
295+
# @param options[:content_type] [String] Optional. The content type for the request. Default application/json
296+
# @param options [Hash] Optional. Body params for the request.
297+
# @return 204 'No Content'
298+
# @see https://developer.okta.com/docs/api/resources/users#user-sessions
299+
# Oktakit.clear_user_sessions('id')
300+
def clear_user_sessions(id, options = {})
301+
delete("/users/#{id}/sessions", options)
302+
end
288303
end
289304
end
290305
end
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
http_interactions:
3+
- request:
4+
method: delete
5+
uri: https://okta-test.okta.com/api/v1/users/00u6o0w6tyuPVEeZr0h7/sessions
6+
body:
7+
encoding: UTF-8
8+
string: "{}"
9+
headers:
10+
User-Agent:
11+
- Oktakit v0.2.0
12+
Accept:
13+
- application/json
14+
Content-Type:
15+
- application/json
16+
Authorization:
17+
- SSWS <<ACCESS_TOKEN>>
18+
response:
19+
status:
20+
code: 204
21+
message:
22+
headers:
23+
date:
24+
- Tue, 11 Dec 2018 21:18:03 GMT
25+
server:
26+
- nginx
27+
public-key-pins-report-only:
28+
- pin-sha256="r5EfzZxQVvQpKo3AgYRaT7X2bDO/kj3ACwmxfdT2zt8="; pin-sha256="MaqlcUgk2mvY/RFSGeSwBRkI+rZ6/dxe/DuQfBT/vnQ=";
29+
pin-sha256="72G5IEvDEWn+EThf3qjR7/bQSWaS2ZSLqolhnO6iyJI="; pin-sha256="rrV6CLCCvqnk89gWibYT0JO6fNQ8cCit7GGoiVTjCOg=";
30+
max-age=60; report-uri="https://okta.report-uri.io/r/default/hpkp/reportOnly"
31+
x-okta-request-id:
32+
- XBApi-GwicbxmsV2U8B2tgAAAbc
33+
p3p:
34+
- CP="HONK"
35+
x-rate-limit-limit:
36+
- '600'
37+
x-rate-limit-remaining:
38+
- '597'
39+
x-rate-limit-reset:
40+
- '1544563086'
41+
cache-control:
42+
- no-cache, no-store
43+
pragma:
44+
- no-cache
45+
expires:
46+
- '0'
47+
x-okta-backend:
48+
- ok2-majorapp04b.aue1p.internal
49+
x-frame-options:
50+
- SAMEORIGIN
51+
strict-transport-security:
52+
- max-age=315360000
53+
set-cookie:
54+
- sid=""; Expires=Thu, 01-Jan-1970 00:00:10 GMT; Path=/, JSESSIONID=7487CD03E393F36BAAC9421A8F4B00DC;
55+
Path=/; Secure; HttpOnly
56+
connection:
57+
- close
58+
body:
59+
encoding: UTF-8
60+
string: ''
61+
http_version:
62+
recorded_at: Tue, 11 Dec 2018 21:18:03 GMT
63+
recorded_with: VCR 2.9.3
64+

spec/client/factors_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
factorType: "sms",
4949
provider: "OKTA",
5050
profile: {
51-
phoneNumber: "+1-613-456-1234"
51+
phoneNumber: "+1-613-456-1234"
5252
})
5353
expect(resp.id).not_to be_nil
5454
end

spec/client/users_spec.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,13 @@
203203
end
204204
end
205205
end
206+
207+
describe '#clear_user_sessions' do
208+
it 'returns 204 no content' do
209+
VCR.use_cassette 'clear_user_sessions' do
210+
_, status = client.clear_user_sessions(USERS_USER_ID)
211+
expect(status).to be(204)
212+
end
213+
end
214+
end
206215
end

0 commit comments

Comments
 (0)