zaikio-oauth_client 0.14.0 → 0.15.0

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: 0ff245bb6a309f304b580e81ad30acc9a91916919697b2df717fdb884d3e4a25
4
- data.tar.gz: c8db756a72615d02de42a58804e23b597f095e709506a6055008a8682cc72bbd
3
+ metadata.gz: fb0748eddd282729e6a9ca264b17a59d58b9822c5e900f1bc3690b2b10549567
4
+ data.tar.gz: 191d4f0652fa8dfb9dae28bbfcd550ef8b2114366ef41ad291f25620011e8d3e
5
5
  SHA512:
6
- metadata.gz: 45d03fc98118ae5c283139628d0b8b9eaf1dd9a5ddcf22a02f1a57d8052365190907627831992976d8607329e404a021516403000b54ee072fbd9bc155bb9a89
7
- data.tar.gz: 6ecae0a7e65289cad9c6691dcdaf3179694db40df26cedefe93cecaf7b16b999617f7931cbbc112116744e418b333c787b4b5e426baf6f6db0591ff6a399e6e7
6
+ metadata.gz: 21c66faa4cd6cad8b787b39f919b0e1c30ec718b912f5442ad0fd4c96b7871a0db798bdf84e798d3ddaf441f8ae96819abea31fad7b4a631b12d2983fef378be
7
+ data.tar.gz: acc5550981b27d38cb986e0b934d4dad992ea7f3c462d9dd1f6c202a304e4cd13bb8e202db070f66f458e3263606601943d1f078d9967125c89b068d82554126
data/README.md CHANGED
@@ -266,6 +266,18 @@ Zaikio::OAuthClient.with_auth(bearer_type: "Organization", bearer_id: "fd61f5f5-
266
266
  end
267
267
  ```
268
268
 
269
+ If you need the token for a certain period (e.g. a long-running job which makes many
270
+ requests in sequence), you can specify the `valid_for` interval when requesting the token.
271
+ By default, it won't return an access token which was due to expire in less than 30
272
+ seconds from now. If there is an existing token, but it was due to expire before the end
273
+ of the validity period, this will go and get a fresh token anyway:
274
+
275
+ ```rb
276
+ Zaikio::OAuthClient.with_auth(..., valid_for: 10.minutes) do |access_token|
277
+ # ...
278
+ end
279
+ ```
280
+
269
281
  ## Use of dummy app
270
282
 
271
283
  You can use the included dummy app as a showcase for the workflow and to adjust your own application. To set up the dummy application properly, go into `test/dummy` and use [puma-dev](https://github.com/puma/puma-dev) like this:
@@ -62,7 +62,7 @@ module Zaikio
62
62
  # * If the token has expired, it will be refreshed using the refresh_token flow
63
63
  # (if this fails, we fallback to getting a new token using client_credentials)
64
64
  # * If the token does not exist, we'll get a new one using the client_credentials flow
65
- def get_access_token(bearer_id:, client_name: nil, bearer_type: "Person", scopes: nil)
65
+ def get_access_token(bearer_id:, client_name: nil, bearer_type: "Person", scopes: nil, valid_for: 30.seconds)
66
66
  client_config = client_config_for(client_name || self.client_name)
67
67
  scopes ||= client_config.default_scopes_for(bearer_type)
68
68
 
@@ -71,7 +71,7 @@ module Zaikio
71
71
  bearer_id: bearer_id,
72
72
  requested_scopes: scopes)
73
73
 
74
- token = token.refresh! if token&.expired?
74
+ token = token.refresh! if token && (token.expired? || token.expires_at < valid_for.from_now)
75
75
 
76
76
  token ||= fetch_new_token(client_config: client_config,
77
77
  bearer_type: bearer_type,
@@ -84,7 +84,7 @@ module Zaikio
84
84
  # would require refreshing.
85
85
  def find_usable_access_token(client_name:, bearer_type:, bearer_id:, requested_scopes:) # rubocop:disable Metrics/MethodLength
86
86
  configuration.logger.debug "Try to fetch token for client_name: #{client_name}, "\
87
- "bearer #{bearer_type}/#{bearer_id}, requested_scopes: #{requested_scopes}"
87
+ "bearer #{bearer_type}/#{bearer_id}, requested_scopes: #{requested_scopes}"
88
88
 
89
89
  fetch_access_token = lambda {
90
90
  Zaikio::AccessToken
@@ -81,7 +81,7 @@ module Zaikio
81
81
 
82
82
  def client_config
83
83
  client_config = Zaikio::OAuthClient.configuration.find!(client_name)
84
- client_config = use_org_config? ? client_config.org_config : client_config
84
+ client_config = client_config.org_config if use_org_config?
85
85
 
86
86
  client_config or raise ActiveRecord::RecordNotFound
87
87
  end
@@ -1,5 +1,5 @@
1
1
  module Zaikio
2
2
  module OAuthClient
3
- VERSION = "0.14.0".freeze
3
+ VERSION = "0.15.0".freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zaikio-oauth_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zaikio GmbH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-18 00:00:00.000000000 Z
11
+ date: 2021-08-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack