servicestack 0.1.1 → 0.1.3

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 991af3e1951fbd5467476753e01f05db5992e7399cb0ac3ca0acfaf909056b8e
4
- data.tar.gz: 0e2dcc59cb68a58911ba105d82ff245aff0001a5e41870324c5c2cd12d31e2f9
3
+ metadata.gz: 2b7903981eedef3d52ed39c54494f5370fa0d3a83abe743289468b9d395eef5c
4
+ data.tar.gz: 93db68996921d3d6eb3368e7414ab97ed23a422d907a90f831aec05bf256d33b
5
5
  SHA512:
6
- metadata.gz: f4c822aad83ce16504e03018f13112a36b3c3added39d5f3d52c3dd5234c9d20bcadf03e8dad3eb8f65c671359c5b7d50e53277ae46304ac8fb68f186bd08c7a
7
- data.tar.gz: 84eadaa862a26af3237499a7d07682243b61ed5b97314ed3f498002e94c2360c938186ff90b423e7a6b4e3dbf404b5cf1323b5b4e318804e7fbdc48f7ac29b0d
6
+ metadata.gz: 16408c56eeda8c631548ad2f38cc236381b075bd8d60700a6703d27b32eaf0e1db43952a6426a4f14333f4c50c725aeb0257fbdcc59b7da6141066ad4b350fec
7
+ data.tar.gz: 4e0aaa64d2dee290002cd659254db4637c65a3b35b3a7b6a69b72353fd280a2e20cc33eb1fb2a0ceb080887aa58d8bd9c9b34a797a8c984e40f131aef1453e64
data/CHANGELOG.md CHANGED
@@ -2,6 +2,20 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [0.1.3]
6
+
7
+ ### Added
8
+
9
+ - `npm run bump` / `npm run release` scripts that tag a version and create the
10
+ GitHub Release, which the `release` workflow publishes to RubyGems
11
+
12
+ ## [0.1.2]
13
+
14
+ ### Added
15
+
16
+ - `on_authentication_required` callback for re-authenticating a client before
17
+ automatically retrying a Request that returned 401 Unauthorized
18
+
5
19
  ## [0.1.1]
6
20
 
7
21
  ### Added
@@ -26,5 +40,7 @@ All notable changes to this project will be documented in this file.
26
40
  - Built-in ServiceStack DTOs referenced by generated DTOs (`ResponseStatus`,
27
41
  `QueryBase`, `QueryResponse`, `Authenticate`, ...)
28
42
 
43
+ [0.1.3]: https://github.com/ServiceStack/servicestack-ruby/releases/tag/v0.1.3
44
+ [0.1.2]: https://github.com/ServiceStack/servicestack-ruby/releases/tag/v0.1.2
29
45
  [0.1.1]: https://github.com/ServiceStack/servicestack-ruby/releases/tag/v0.1.1
30
46
  [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
@@ -217,6 +236,25 @@ rake test # unit tests
217
236
  rake test:integration # integration tests against test.servicestack.net
218
237
  ```
219
238
 
239
+ ## Releasing
240
+
241
+ Releases are cut with npm scripts and published by the `release` GitHub Action:
242
+
243
+ ```bash
244
+ npm run bump # 0.1.0 -> 0.1.1 (also `-- minor`, `-- major`, `-- 1.2.3`)
245
+ # describe the release in CHANGELOG.md, then
246
+ npm run release
247
+ ```
248
+
249
+ Or in a single step:
250
+
251
+ ```bash
252
+ npm run release -- patch
253
+ ```
254
+
255
+ `npm run release` tags the version, pushes it and creates the GitHub Release,
256
+ which triggers the workflow that runs the tests and publishes it to [RubyGems](https://rubygems.org/gems/servicestack).
257
+
220
258
  ## License
221
259
 
222
260
  BSD-3-Clause. See [LICENSE](LICENSE).
@@ -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 && refresh_access_token
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ServiceStack
4
- VERSION = '0.1.1'
4
+ VERSION = '0.1.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servicestack
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - ServiceStack
@@ -49,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
- rubygems_version: 3.7.2
52
+ rubygems_version: 3.6.9
53
53
  specification_version: 4
54
54
  summary: Typed Ruby Client Library for consuming ServiceStack APIs
55
55
  test_files: []