standard_id 0.63.0 → 0.64.1

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: f4338b3e28da791aae773a472cbc7eda8a0fcc4d94ee2513f733e84f9b4185a5
4
- data.tar.gz: 23c17a0ea7040d29787ebd23671047eb239f8cf73567c11414f0097f53f02ded
3
+ metadata.gz: bc6e2b7114dad7aa0475bd6fcd96f6a4c29c34eb91a2667cfaab83ee4f17089d
4
+ data.tar.gz: 7bf5da56fcc0572da349de796a74442585f529a3522bdcdaf9c1421e63cc6fc4
5
5
  SHA512:
6
- metadata.gz: e4c3dbe4a53c0a84cdc99d73fd5e46e5a820c1ad60f3fd23e5a71bd280aae8c184fcf42e814c9ef6d6e754bd519c839d4a682996a3092730eec49fd012aa646c
7
- data.tar.gz: 43fb59a7c70eef841e53b986420a3fcbe99463de22f4d4b9cc981891be80e311aed0baf720c6df8ef149f23eb35138e552fb435280f2f7460ff8de203c87b38e
6
+ metadata.gz: df80d0509429e338f1c6be7057ddf5606ef5b70555a90e1e6b8344cf05b341d2836a729590f2bd596fd2faf81b97d5e0d22eb1cab9ec5a60f2b02373f0c8fc40
7
+ data.tar.gz: dc8312147249dd52500a68f113523fae4926171a7458fb27ff24b33ef21686dd646668b0cdea0cc8181d2d1dc04c20810b8bb483dee93cd8744959d4a1886104
data/CHANGELOG.md CHANGED
@@ -7,6 +7,41 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.64.1] - 2026-11-25
11
+
12
+ ### Fixed
13
+
14
+ - **Errors the `network_wrapper` passes through now survive a provider's error mapping.** An error
15
+ the wrapper lets out unchanged (one raised after the block returned, a programming error, or one
16
+ listed in `config.network_wrapper_passthrough_errors`) was still turned into an `OAuthError` by
17
+ `StandardId::Providers::Base#rescue_to_oauth_error`, which wraps every plugin sign-in call (code
18
+ exchange, JWKS, tokeninfo, userinfo). The sign-in failed as a handled 400 `invalid_request` such as
19
+ "Failed to fetch Google JWKS: no circuit registered for :oauth_google", which named the circuit and
20
+ never reached the error tracker. `StandardId::NetworkWrapper` now marks such errors
21
+ (`StandardId::NetworkWrapper.passed_through?`) and `rescue_to_oauth_error` re-raises them
22
+ unchanged. The request's own errors (timeouts, refused connections) and refusals that become
23
+ `ProviderUnavailableError` map as before.
24
+
25
+ ## [0.64.0] - 2026-11-25
26
+
27
+ ### Added
28
+
29
+ - **`config.network_wrapper_passthrough_errors`.** Errors the host's `network_wrapper` raises
30
+ that mean its own setup is wrong, not that the provider is down, reach the caller unchanged
31
+ instead of becoming `ProviderUnavailableError`. An example is `StandardCircuit::UnknownCircuit`
32
+ for a circuit that was never registered. Without the setting, such a misconfiguration shows
33
+ users "temporarily unavailable" and never reaches the error tracker. Entries are classes or
34
+ class-name Strings; a String is resolved when a wrapper error is handled, so it may name a
35
+ class from a gem that isn't loaded, and a name that resolves to nothing is ignored. Defaults
36
+ to `[]`, so nothing changes unless you set it.
37
+ - **`Retry-After` for a refused provider call.** `ProviderUnavailableError` now has
38
+ `retry_after` (Integer seconds, or nil). `NetworkWrapper` fills it in from the wrapper's
39
+ error: a `retry_after` that is a `Time` (seconds until then) or a number of seconds, or else
40
+ `cool_off_time` in seconds, as Stoplight's `RedLight` provides. It is duck-typed and assumes
41
+ no breaker library. The API's 503 `temporarily_unavailable` responses, such as
42
+ `/api/oauth/callback/:provider`, then send a `Retry-After` header. Errors that say nothing
43
+ get no header, as before.
44
+
10
45
  ## [0.63.0] - 2026-11-24
11
46
 
12
47
  ### Added
data/README.md CHANGED
@@ -786,6 +786,10 @@ breaker that turns the request's failure into its own error), StandardId raises
786
786
  `cause`. That is an `OAuthError`, so the web callback sends the user back to the
787
787
  login page with "Google is temporarily unavailable" and the API answers 503
788
788
  `temporarily_unavailable`. The circuit's own message never reaches the user.
789
+ When the wrapper's error says how long to wait, the 503 carries a `Retry-After`
790
+ header: StandardId reads `retry_after` (a `Time` or a number of seconds) or,
791
+ failing that, `cool_off_time` (seconds) from it, as Stoplight's `RedLight`
792
+ provides. It knows no breaker library, so any error with those methods works.
789
793
 
790
794
  Some errors from the wrapper are passed through unchanged:
791
795
  - a `StandardId::OAuthError` it raises on purpose
@@ -794,6 +798,29 @@ Some errors from the wrapper are passed through unchanged:
794
798
  - a programming error (`NameError`/`NoMethodError`, `TypeError`,
795
799
  `ArgumentError`; see `StandardId::NetworkWrapper::PROGRAMMING_ERRORS`), so
796
800
  your error tracker sees the bug
801
+ - an error you list in `config.network_wrapper_passthrough_errors`
802
+
803
+ That last setting is for errors that mean your own setup is wrong rather than
804
+ the provider being down. `StandardCircuit.run` raises
805
+ `StandardCircuit::UnknownCircuit` (not a programming error) when no circuit is
806
+ registered under the name, and without the setting that misconfiguration would
807
+ look like an outage to users and never reach your error tracker:
808
+
809
+ ```ruby
810
+ c.network_wrapper_passthrough_errors = ["StandardCircuit::UnknownCircuit"]
811
+ ```
812
+
813
+ Entries are classes or class names. A name is resolved when a wrapper error is
814
+ handled, so it may name a class from a gem that isn't loaded; a name that
815
+ resolves to nothing is ignored. An error passes through when it `is_a?` any
816
+ entry. Errors the request itself raised are passed through regardless.
817
+
818
+ A passed-through error also gets past the provider plugins' own error mapping
819
+ (`rescue_to_oauth_error`, which turns other failures into an `OAuthError`), so
820
+ it propagates out of the sign-in instead of becoming a 400 that names your
821
+ circuit (fixed in 0.64.1). `StandardId::NetworkWrapper.passed_through?(error)`
822
+ tells you whether an error left the wrapper this way, for a plugin with its own
823
+ rescue around a provider request.
797
824
 
798
825
  `provider` is the plugin's name
799
826
  (`:google`, `:apple`, ...), or `:standard_id` for a plugin release that does not
@@ -643,10 +643,19 @@ StandardId.configure do |c|
643
643
  # the request as a block; must call the block and return its result. A
644
644
  # refusal by the wrapper itself (an open circuit) becomes
645
645
  # StandardId::ProviderUnavailableError, so sign-in fails as "temporarily
646
- # unavailable" (API: 503) without the circuit's message.
646
+ # unavailable" (API: 503, with Retry-After when the refusal says how long
647
+ # to wait) without the circuit's message.
647
648
  # Default: nil (the request runs directly)
648
649
  # c.network_wrapper = ->(provider:, &b) { StandardCircuit.run(:"oauth_#{provider}", &b) }
649
650
 
651
+ # Errors network_wrapper raises that mean your setup is wrong, not that the
652
+ # provider is down (a circuit that was never registered, say). They reach
653
+ # the caller and your error tracker unchanged instead of becoming
654
+ # ProviderUnavailableError. Classes or class names; a name that resolves to
655
+ # nothing (its gem isn't loaded) is ignored.
656
+ # Default: []
657
+ # c.network_wrapper_passthrough_errors = ["StandardCircuit::UnknownCircuit"]
658
+
650
659
  # Receives errors StandardId handles and carries on from (a subscriber that
651
660
  # raised after its change committed). Receives (error, context).
652
661
  # Default: nil (Rails.error.report(error, handled: true, source: "standard_id"))
@@ -179,15 +179,30 @@ StandardId::ConfigSchema.define do
179
179
  # (timeouts, refused connections) raises inside the wrapper and, re-raised,
180
180
  # reaches the caller unchanged. A refusal by the wrapper itself (an open
181
181
  # circuit) becomes StandardId::ProviderUnavailableError, `cause` set to it,
182
- # so a sign-in fails as "temporarily unavailable" (API: 503) without the
183
- # circuit's message. Programming errors in the wrapper, and errors it
184
- # raises after the block returned, pass through unchanged (see
185
- # StandardId::NetworkWrapper).
182
+ # so a sign-in fails as "temporarily unavailable" (API: 503, with
183
+ # Retry-After when the refusal says how long to wait) without the
184
+ # circuit's message. Programming errors in the wrapper, errors listed in
185
+ # network_wrapper_passthrough_errors, and errors it raises after the
186
+ # block returned pass through unchanged (see StandardId::NetworkWrapper).
186
187
  # nil (the default) runs the block directly.
187
188
  #
188
189
  # c.network_wrapper = ->(provider:, &b) { StandardCircuit.run(:"oauth_#{provider}", &b) }
189
190
  field :network_wrapper, type: :any, default: nil
190
191
 
192
+ # network_wrapper_passthrough_errors: errors network_wrapper raises that
193
+ # mean the host's own setup is wrong, not that the provider is down, such
194
+ # as a circuit that was never registered. They reach the caller (and the
195
+ # error tracker) unchanged instead of becoming
196
+ # StandardId::ProviderUnavailableError. An error passes through when it
197
+ # `is_a?` any entry.
198
+ # Entries: classes, or class names as Strings. A String is resolved
199
+ # when a wrapper error is handled, so it may name a class from a gem
200
+ # that is not loaded; a name that resolves to nothing is ignored.
201
+ # [] (the default) passes none through.
202
+ #
203
+ # c.network_wrapper_passthrough_errors = ["StandardCircuit::UnknownCircuit"]
204
+ field :network_wrapper_passthrough_errors, type: :array, default: -> { [] }
205
+
191
206
  # error_reporter: receives errors StandardId handles and carries on from —
192
207
  # today, an event subscriber that raised after the change it reports had
193
208
  # already committed (a completed password reset, a password rehash, a
@@ -229,8 +229,14 @@ module StandardId
229
229
  # @return [Symbol, nil] the provider the request was for (`:google`, ...)
230
230
  attr_reader :provider
231
231
 
232
- def initialize(message = nil, provider: nil)
232
+ # @return [Integer, nil] seconds the wrapper's error says to wait before
233
+ # retrying (StandardId::NetworkWrapper reads it from the error), sent
234
+ # by the API as a Retry-After header; nil when it doesn't say
235
+ attr_reader :retry_after
236
+
237
+ def initialize(message = nil, provider: nil, retry_after: nil)
233
238
  @provider = provider
239
+ @retry_after = retry_after
234
240
  super(message || "#{provider_label(provider)} is temporarily unavailable")
235
241
  end
236
242
 
@@ -23,11 +23,23 @@ module StandardId
23
23
  # 4. A programming error in the wrapper (PROGRAMMING_ERRORS: a typo, an
24
24
  # unloaded constant, a wrong call) reaches the caller as is, so it is
25
25
  # reported as the bug it is, not shown as an outage.
26
- # 5. Anything else (an open circuit that never ran the block, a breaker
26
+ # 5. An error the host listed in `config.network_wrapper_passthrough_errors`
27
+ # (a misconfiguration of its own, such as a circuit that was never
28
+ # registered) reaches the caller as is, for the same reason.
29
+ # 6. Anything else (an open circuit that never ran the block, a breaker
27
30
  # that turns the request's failure into its own error) becomes
28
31
  # StandardId::ProviderUnavailableError, with the wrapper's error as
29
32
  # `cause`. Callers therefore need no knowledge of the host's
30
- # circuit-breaker library to map an outage.
33
+ # circuit-breaker library to map an outage. When the wrapper's error
34
+ # says how long to wait (see .retry_after_from), the
35
+ # ProviderUnavailableError carries it as `retry_after`, which the API
36
+ # sends as a Retry-After header.
37
+ #
38
+ # An error let out under rules 3, 4 or 5 is marked as passed through (see
39
+ # .passed_through?), so StandardId::Providers::Base#rescue_to_oauth_error,
40
+ # which wraps every provider sign-in call, re-raises it unchanged instead of
41
+ # turning it into an OAuthError. The block's own errors (rule 2) are not
42
+ # marked: they map exactly as they do with no wrapper.
31
43
  #
32
44
  # Non-StandardError exceptions (Interrupt, ...) are never touched.
33
45
  module NetworkWrapper
@@ -35,13 +47,16 @@ module StandardId
35
47
  # because the provider is down. NameError covers NoMethodError.
36
48
  PROGRAMMING_ERRORS = [NameError, TypeError, ArgumentError].freeze
37
49
 
50
+ # Extended into an error the wrapper let out under rules 3 to 5.
51
+ module PassedThrough; end
52
+
38
53
  module_function
39
54
 
40
55
  # @param provider [Symbol, String, nil] the remote service (`:google`,
41
56
  # `:apple`, ...), handed to the wrapper as `provider:`
42
57
  # @return whatever the block (through the wrapper) returns
43
58
  # @raise [StandardId::ProviderUnavailableError] the wrapper refused the
44
- # request (rule 5 above)
59
+ # request (rule 6 above)
45
60
  def run(provider:, &block)
46
61
  wrapper = StandardId.config.network_wrapper
47
62
  return yield unless wrapper.respond_to?(:call)
@@ -68,11 +83,56 @@ module StandardId
68
83
  raise
69
84
  rescue StandardError => e
70
85
  raise if raised.any? { |error| error.equal?(e) }
71
- raise if returned
72
- raise if PROGRAMMING_ERRORS.any? { |klass| e.is_a?(klass) }
86
+ if returned || PROGRAMMING_ERRORS.any? { |klass| e.is_a?(klass) } || passthrough_errors.any? { |klass| e.is_a?(klass) }
87
+ # Never frozen: Ruby raises a copy of a frozen exception.
88
+ e.extend(PassedThrough) unless e.frozen?
89
+ raise
90
+ end
91
+
92
+ raise StandardId::ProviderUnavailableError.new(provider: provider, retry_after: retry_after_from(e)), cause: e
93
+ end
94
+ end
73
95
 
74
- raise StandardId::ProviderUnavailableError.new(provider: provider), cause: e
96
+ # Whether the wrapper let this error out on purpose (rules 3 to 5), so a
97
+ # caller that turns errors into OAuthErrors must re-raise it unchanged.
98
+ #
99
+ # @param error [Exception]
100
+ # @return [Boolean]
101
+ def passed_through?(error)
102
+ error.is_a?(PassedThrough)
103
+ end
104
+
105
+ # The classes in `config.network_wrapper_passthrough_errors`. A String
106
+ # names a class that may not be loaded (it may come from a gem the host
107
+ # has not required), so it is resolved on each call and skipped while it
108
+ # names nothing.
109
+ #
110
+ # @return [Array<Module>]
111
+ def passthrough_errors
112
+ Array(StandardId.config.network_wrapper_passthrough_errors).filter_map do |entry|
113
+ klass = entry.is_a?(Module) ? entry : entry.to_s.safe_constantize
114
+ klass if klass.is_a?(Module)
75
115
  end
76
116
  end
117
+
118
+ # How long, in whole seconds, the wrapper's error says to wait before
119
+ # retrying, or nil when it doesn't say. Duck-typed, so no breaker library
120
+ # is assumed: a `retry_after` that is a Time (when to retry) or a Numeric
121
+ # (seconds) decides; without one, `cool_off_time` in seconds. Stoplight's
122
+ # RedLight has both, with `retry_after` nil while a light is locked red.
123
+ #
124
+ # @param error [Exception] the wrapper's error
125
+ # @return [Integer, nil] a positive number of seconds, or nil
126
+ def retry_after_from(error)
127
+ value = error.retry_after if error.respond_to?(:retry_after)
128
+ value -= Time.now if value.is_a?(Time)
129
+ value = error.cool_off_time if !value.is_a?(Numeric) && error.respond_to?(:cool_off_time)
130
+
131
+ value.ceil if value.is_a?(Numeric) && value.positive?
132
+ rescue StandardError
133
+ # Only a hint for a header: a host error whose accessor misbehaves must
134
+ # not replace the ProviderUnavailableError being raised.
135
+ nil
136
+ end
77
137
  end
78
138
  end
@@ -453,6 +453,12 @@ module StandardId
453
453
  # errors — is wrapped so callers only ever handle OAuthError, with the
454
454
  # original exception kept as `cause`.
455
455
  #
456
+ # An error the host's network_wrapper let out on purpose (see
457
+ # StandardId::NetworkWrapper.passed_through?: a programming error, a
458
+ # listed misconfiguration such as an unregistered circuit, or an error
459
+ # after the request went through) propagates unchanged too, so it
460
+ # reaches the error tracker instead of becoming a handled 400.
461
+ #
456
462
  # @param message_prefix [String, nil] Prepended to the wrapped error's
457
463
  # message, e.g. "Failed to fetch JWK" → "Failed to fetch JWK: <msg>"
458
464
  # @return [Object] the block's return value
@@ -471,6 +477,8 @@ module StandardId
471
477
  rescue StandardId::OAuthError
472
478
  raise
473
479
  rescue StandardError => e
480
+ raise if StandardId::NetworkWrapper.passed_through?(e)
481
+
474
482
  message = message_prefix ? "#{message_prefix}: #{e.message}" : e.message
475
483
  raise StandardId::OAuthError, message, cause: e
476
484
  end
@@ -1,3 +1,3 @@
1
1
  module StandardId
2
- VERSION = "0.63.0"
2
+ VERSION = "0.64.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_id
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.63.0
4
+ version: 0.64.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rarebit One