servicestack 0.1.1 → 0.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/README.md +19 -0
- data/lib/servicestack/json_service_client.rb +22 -2
- data/lib/servicestack/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 422e88b02d244852ff3d8941817d5fc6c22c58c2a7698458b4d2d96df75af2bf
|
|
4
|
+
data.tar.gz: 9b2941734b9154d258de44f156e2e66b600f6042825535b017cf81699bcaf6da
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '09d3557ceda3563802cedbdcf7feddcadb4ccf5251994c00ecdadefa5417fab664429502b7a94379c53e4136f76e2337075d76f07a22cb015c990cbffb59ea7d'
|
|
7
|
+
data.tar.gz: 8abcf83d19d0530c7873a4a6993fc11390305379657f8db395e7a60a07e2faede986dc807e585a68bfd399aeb2b4b6829bbcfa08b42347568ecd304e14a19c43
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,13 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [0.1.2]
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- `on_authentication_required` callback for re-authenticating a client before
|
|
10
|
+
automatically retrying a Request that returned 401 Unauthorized
|
|
11
|
+
|
|
5
12
|
## [0.1.1]
|
|
6
13
|
|
|
7
14
|
### Added
|
|
@@ -26,5 +33,6 @@ All notable changes to this project will be documented in this file.
|
|
|
26
33
|
- Built-in ServiceStack DTOs referenced by generated DTOs (`ResponseStatus`,
|
|
27
34
|
`QueryBase`, `QueryResponse`, `Authenticate`, ...)
|
|
28
35
|
|
|
36
|
+
[0.1.2]: https://github.com/ServiceStack/servicestack-ruby/releases/tag/v0.1.2
|
|
29
37
|
[0.1.1]: https://github.com/ServiceStack/servicestack-ruby/releases/tag/v0.1.1
|
|
30
38
|
[0.1.0]: https://github.com/ServiceStack/servicestack-ruby/releases/tag/v0.1.0
|
data/README.md
CHANGED
|
@@ -162,6 +162,25 @@ refreshed and the failed Request retried:
|
|
|
162
162
|
client.set_refresh_token(refresh_token)
|
|
163
163
|
```
|
|
164
164
|
|
|
165
|
+
### Transparently handle 401 Unauthorized Responses
|
|
166
|
+
|
|
167
|
+
If the Server returns a 401 Unauthorized Response either because the client was
|
|
168
|
+
unauthenticated or its Bearer Token or API Key had expired, use the
|
|
169
|
+
`on_authentication_required` callback to re-configure the client before the
|
|
170
|
+
original Request is automatically retried:
|
|
171
|
+
|
|
172
|
+
```ruby
|
|
173
|
+
client.on_authentication_required = lambda { |c|
|
|
174
|
+
c.authenticate(user_name, password)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
# Automatically retries Requests returning 401 Responses
|
|
178
|
+
res = client.send(Secured.new)
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
A configured Refresh Token takes precedence over the callback, which is only
|
|
182
|
+
used when no Refresh Token is set or refreshing it failed.
|
|
183
|
+
|
|
165
184
|
### Batched Requests
|
|
166
185
|
|
|
167
186
|
```ruby
|
|
@@ -71,7 +71,7 @@ module ServiceStack
|
|
|
71
71
|
attr_accessor :base_url, :reply_base_url, :oneway_base_url, :headers,
|
|
72
72
|
:bearer_token, :refresh_token, :refresh_token_uri,
|
|
73
73
|
:user_name, :password, :request_filter, :response_filter,
|
|
74
|
-
:timeout, :cookies
|
|
74
|
+
:timeout, :cookies, :on_authentication_required
|
|
75
75
|
|
|
76
76
|
class << self
|
|
77
77
|
# Filters applied to every Request and Response of all clients.
|
|
@@ -309,7 +309,7 @@ module ServiceStack
|
|
|
309
309
|
capture_cookies(response)
|
|
310
310
|
|
|
311
311
|
status_code = response.code.to_i
|
|
312
|
-
if status_code == 401 && retry_on_auth_failure &&
|
|
312
|
+
if status_code == 401 && retry_on_auth_failure && handle_authentication_required
|
|
313
313
|
return execute(method, url, body, retry_on_auth_failure: false, content_type: content_type)
|
|
314
314
|
end
|
|
315
315
|
|
|
@@ -375,6 +375,26 @@ module ServiceStack
|
|
|
375
375
|
end
|
|
376
376
|
end
|
|
377
377
|
|
|
378
|
+
# Re-authenticates the client after a Request returned 401 Unauthorized,
|
|
379
|
+
# returning whether the Request should be retried.
|
|
380
|
+
#
|
|
381
|
+
# Uses the Refresh Token when configured, otherwise the
|
|
382
|
+
# `on_authentication_required` callback.
|
|
383
|
+
def handle_authentication_required
|
|
384
|
+
return true if refresh_access_token
|
|
385
|
+
return false if @on_authentication_required.nil?
|
|
386
|
+
|
|
387
|
+
if @on_authentication_required.arity.zero?
|
|
388
|
+
@on_authentication_required.call
|
|
389
|
+
else
|
|
390
|
+
@on_authentication_required.call(self)
|
|
391
|
+
end
|
|
392
|
+
true
|
|
393
|
+
rescue StandardError
|
|
394
|
+
# Re-authenticating failed, return the original 401 Response
|
|
395
|
+
false
|
|
396
|
+
end
|
|
397
|
+
|
|
378
398
|
def refresh_access_token
|
|
379
399
|
return false if @refresh_token.to_s.empty?
|
|
380
400
|
|
data/lib/servicestack/version.rb
CHANGED