standard_id-apple 0.7.0 → 0.9.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: 9a3e07c309c99df7cef0af887b983707a504e9c68966899bb9f5a173e7fa6e45
4
- data.tar.gz: fe8506b6efa0b7fad211136546e04f318057bcd53bb4961d61dcfd6352ec0118
3
+ metadata.gz: 34ac427042ac9a5d6ed32aeda4eeed8c2bb4c481778b646b39e1a030de03e988
4
+ data.tar.gz: 970ae234cf4ded4a91c416735f3561774e91474f3e393544297f5347970a4aeb
5
5
  SHA512:
6
- metadata.gz: 723d58e82c79eb36a8c963e9f94e68718df906af0f498831e6095bc8ec7774f806a0ab4e8661942401654d055bf42fa96633a7ddca0d38d8f719721bb0a8419a
7
- data.tar.gz: ca5b3cdd9a2a6ce0ab8dfb47dfc9291442d3f62e9149c00630088da543d512d0537540b92ee488159ef69d2d02ee39781075ff0ab03b6c998448afb881afdc74
6
+ metadata.gz: 2ccc7df07a7e84a4582675847b6d8b88f6723c29e069fc69e4214feeaac818b92219639cc712aae6bd6f07359c8d3bf55b467c527f166a868ff567ebd64a3412
7
+ data.tar.gz: 7ec6bfda65dea50d178fbdcca251de5046a62cf14bc17c352f2c9f416be02ac0f5a80c4551ad7b20a4f368f3ccc4e59ba7af54c1ee32d020cb4f439ffc8fd4ab
data/CHANGELOG.md CHANGED
@@ -7,6 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.9.0] - 2026-11-23
11
+
12
+ ### Added
13
+
14
+ - **Every request names the provider to `StandardId::HttpClient`** (`provider: :apple`): the web
15
+ and native code exchanges, token revocation and the JWKS download. A standard_id that takes the
16
+ keyword (0.61.0 and later) hands it to the host's `config.network_wrapper`, so a circuit
17
+ breaker or tracing span can tell Apple's calls apart. Against older standard_id releases the
18
+ keyword is left out, detected from each method's parameters, so the `~> 0.42` requirement is
19
+ unchanged. An error the wrapper raises itself (an open circuit) is not one of the transport
20
+ errors `exchange_authorization_code` and `revoke` turn into `TokenRequestError`, so it reaches
21
+ the caller as is.
22
+
23
+ ## [0.8.0] - 2026-10-08
24
+
25
+ ### Added
26
+
27
+ - **`apple_redirect_uri`** (optional, ENV fallback `APPLE_REDIRECT_URI`): the
28
+ return URL web-flow codes are authorized against when the caller exchanges
29
+ them without one — normally `https://<host>/auth/callback_mobile/apple`,
30
+ registered on the Services ID.
31
+
32
+ ### Fixed
33
+
34
+ - **`flow=web` code exchanges through the API callback** (e.g. Android signing
35
+ in through Apple's web flow) sent no `redirect_uri` to Apple's token
36
+ endpoint, so Apple rejected them with `invalid_grant`. `resolve_params` now
37
+ fills the configured `apple_redirect_uri` for the web flow when the caller
38
+ passed none. A caller's `redirect_uri` (the browser callback's) still wins,
39
+ and the native flow is unchanged. No-op until `apple_redirect_uri` is set.
40
+
10
41
  ## [0.7.0] - 2026-10-06
11
42
 
12
43
  ### Added
data/README.md CHANGED
@@ -45,6 +45,7 @@ configuration block, in the `social` scope:
45
45
  StandardId.configure do |config|
46
46
  config.social.apple_client_id = ENV["APPLE_CLIENT_ID"]
47
47
  config.social.apple_mobile_client_id = ENV["APPLE_MOBILE_CLIENT_ID"] # optional
48
+ config.social.apple_redirect_uri = ENV["APPLE_REDIRECT_URI"] # optional, see Flows
48
49
  config.social.apple_team_id = ENV["APPLE_TEAM_ID"]
49
50
  config.social.apple_key_id = ENV["APPLE_KEY_ID"]
50
51
  config.social.apple_private_key = ENV["APPLE_PRIVATE_KEY"]
@@ -62,6 +63,7 @@ variable named after it, upper-cased:
62
63
  |---|---|
63
64
  | `apple_client_id` | `APPLE_CLIENT_ID` |
64
65
  | `apple_mobile_client_id` | `APPLE_MOBILE_CLIENT_ID` |
66
+ | `apple_redirect_uri` | `APPLE_REDIRECT_URI` |
65
67
  | `apple_team_id` | `APPLE_TEAM_ID` |
66
68
  | `apple_key_id` | `APPLE_KEY_ID` |
67
69
  | `apple_private_key` | `APPLE_PRIVATE_KEY` (deprecated fallback: `APPLE_PRIVATE_KEY_PEM`) |
@@ -103,6 +105,14 @@ UI while its native sign-in keeps working.
103
105
  | Native `id_token` (`/api/oauth/callback/apple`) | `apple_mobile_client_id` | no |
104
106
  | Web flow on Android etc. (`flow=web` on the API callback, redirects back into the app) | `apple_client_id` | yes |
105
107
 
108
+ Apple only exchanges a web-flow code when the token request carries the same
109
+ `redirect_uri` the authorization used. The browser callback passes its own
110
+ URL. The API callback passes none, so for `flow=web` there set
111
+ `apple_redirect_uri` to the return URL those codes are authorized against,
112
+ normally the mobile bounce `https://<host>/auth/callback_mobile/apple`
113
+ (registered on the Services ID). A `redirect_uri` the caller passes always
114
+ wins, and the native flow never sends one.
115
+
106
116
  Apple's signing keys (JWKS) are fetched through `StandardId::HttpClient`
107
117
  (timeouts, private-address guard) and cached in-process for an hour; a token
108
118
  signed with an unknown key triggers one early refetch, at most once a minute.
@@ -2,7 +2,7 @@
2
2
 
3
3
  # Apple Sign In credentials for StandardId.
4
4
  #
5
- # These five fields are declared by the standard_id-apple gem, NOT by
5
+ # These six fields are declared by the standard_id-apple gem, NOT by
6
6
  # standard_id — they do not exist unless this gem is in the Gemfile, on any
7
7
  # standard_id version. Removing the gem and leaving this file behind raises
8
8
  # `StandardId::ConfigurationError: Unknown field 'apple_client_id' for scope
@@ -15,10 +15,10 @@
15
15
  #
16
16
  # ENV: on standard_id >= 0.42 a field this file does not assign falls back to
17
17
  # the ENV variable named after it, upper-cased — APPLE_CLIENT_ID,
18
- # APPLE_MOBILE_CLIENT_ID, APPLE_TEAM_ID, APPLE_KEY_ID, APPLE_PRIVATE_KEY — which
19
- # are the names used below. The assignments are kept so the wiring is visible;
20
- # delete any you prefer to leave to the fallback, or point one at another
21
- # source (e.g. Rails credentials).
18
+ # APPLE_MOBILE_CLIENT_ID, APPLE_REDIRECT_URI, APPLE_TEAM_ID, APPLE_KEY_ID,
19
+ # APPLE_PRIVATE_KEY — which are the names used below. The assignments are kept
20
+ # so the wiring is visible; delete any you prefer to leave to the fallback, or
21
+ # point one at another source (e.g. Rails credentials).
22
22
  #
23
23
  # apple_client_id switches the web flow on. While it is set, StandardId's boot
24
24
  # check requires apple_team_id, apple_key_id and apple_private_key (warns by
@@ -32,6 +32,12 @@ StandardId.configure do |config|
32
32
  # on a web-only app is correct — don't point it at APPLE_CLIENT_ID.
33
33
  config.social.apple_mobile_client_id = ENV["APPLE_MOBILE_CLIENT_ID"]
34
34
 
35
+ # Optional: the return URL web-flow codes exchanged through the API callback
36
+ # (`flow=web`, e.g. Android) were authorized against — normally
37
+ # https://<host>/auth/callback_mobile/apple, registered on the Services ID.
38
+ # Apple rejects the exchange (invalid_grant) without it.
39
+ config.social.apple_redirect_uri = ENV["APPLE_REDIRECT_URI"]
40
+
35
41
  config.social.apple_team_id = ENV["APPLE_TEAM_ID"]
36
42
  config.social.apple_key_id = ENV["APPLE_KEY_ID"]
37
43
 
@@ -85,11 +85,16 @@ module StandardId
85
85
  #
86
86
  # ENV fallbacks (standard_id >= 0.42) use the upper-cased field names:
87
87
  # APPLE_CLIENT_ID, APPLE_MOBILE_CLIENT_ID, APPLE_PRIVATE_KEY,
88
- # APPLE_KEY_ID, APPLE_TEAM_ID.
88
+ # APPLE_KEY_ID, APPLE_TEAM_ID, APPLE_REDIRECT_URI.
89
+ #
90
+ # `apple_redirect_uri` is optional: the return URL a web-flow code
91
+ # was issued against, for callers that exchange the code without
92
+ # passing one (see #resolve_params).
89
93
  def config_schema
90
94
  {
91
95
  apple_client_id: { type: :string, default: nil },
92
96
  apple_mobile_client_id: { type: :string, default: nil },
97
+ apple_redirect_uri: { type: :string, default: nil },
93
98
  apple_private_key: { type: :string, default: -> { legacy_private_key_from_env }, required: true },
94
99
  apple_key_id: { type: :string, default: nil, required: true },
95
100
  apple_team_id: { type: :string, default: nil, required: true }
@@ -113,11 +118,24 @@ module StandardId
113
118
 
114
119
  # The web flow authenticates against the Services ID, the native flow
115
120
  # against the app's bundle ID.
121
+ #
122
+ # A web-flow code must be exchanged with the redirect_uri it was
123
+ # authorized against, or Apple answers invalid_grant. The browser
124
+ # callback passes its own URL. The API callback (`flow=web`, e.g.
125
+ # Android signing in through Apple's web flow and bouncing back via
126
+ # `/auth/callback_mobile/apple`) passes none, so the configured
127
+ # `apple_redirect_uri` fills the gap. A redirect_uri the caller did
128
+ # pass always wins; the native flow never gets one.
116
129
  def resolve_params(params, context: {})
117
130
  flow = context[:flow] || :web
118
- client_id = flow == :mobile ? StandardId.config.apple_mobile_client_id : StandardId.config.apple_client_id
131
+ return params.merge(client_id: StandardId.config.apple_mobile_client_id) if flow == :mobile
119
132
 
120
- params.merge(client_id: client_id)
133
+ resolved = params.merge(client_id: StandardId.config.apple_client_id)
134
+ configured_redirect_uri = StandardId.config.apple_redirect_uri
135
+ if resolved[:redirect_uri].blank? && configured_redirect_uri.present?
136
+ resolved[:redirect_uri] = configured_redirect_uri
137
+ end
138
+ resolved
121
139
  end
122
140
 
123
141
  def exchange_code_for_user_info(code:, redirect_uri:, client_id: StandardId.config.apple_client_id, nonce: nil)
@@ -131,7 +149,7 @@ module StandardId
131
149
  code: code,
132
150
  grant_type: "authorization_code",
133
151
  redirect_uri: redirect_uri
134
- })
152
+ }, **http_provider(:post_form))
135
153
 
136
154
  unless token_response.is_a?(Net::HTTPSuccess)
137
155
  raise StandardId::InvalidRequestError,
@@ -329,7 +347,7 @@ module StandardId
329
347
  # which hold the code/token and the client secret.
330
348
  def post_to_apple(endpoint, params, failure:)
331
349
  response = begin
332
- HttpClient.post_form(endpoint, params)
350
+ HttpClient.post_form(endpoint, params, **http_provider(:post_form))
333
351
  rescue Timeout::Error, IOError, SocketError, SystemCallError, OpenSSL::SSL::SSLError, HttpClient::SsrfError => e
334
352
  raise StandardId::Apple::TokenRequestError, "#{failure}: #{e.class.name}"
335
353
  end
@@ -413,7 +431,7 @@ module StandardId
413
431
  def download_jwks
414
432
  rescue_to_oauth_error("Failed to fetch Apple JWKS") do
415
433
  uri, resolved_ip = HttpClient.send(:validate_url!, JWKS_URI)
416
- response = HttpClient.send(:start_connection, uri, resolved_ip: resolved_ip) do |http|
434
+ response = HttpClient.send(:start_connection, uri, resolved_ip: resolved_ip, **http_provider(:start_connection)) do |http|
417
435
  http.request(Net::HTTP::Get.new(uri))
418
436
  end
419
437
  raise StandardId::OAuthError, "Failed to fetch Apple JWKS: HTTP #{response.code}" unless response.is_a?(Net::HTTPSuccess)
@@ -425,6 +443,18 @@ module StandardId
425
443
  end
426
444
  end
427
445
 
446
+ # `provider: :apple` for StandardId::HttpClient, which hands it to the
447
+ # host's `config.network_wrapper` (e.g. one circuit per provider). Only
448
+ # standard_id releases after 0.60.0 take the keyword, and this plugin
449
+ # still supports older ones, so it is passed only when the method
450
+ # declares it. Read on each call rather than cached: Method#parameters
451
+ # costs nothing next to the request itself.
452
+ def http_provider(method_name)
453
+ parameters = HttpClient.method(method_name).parameters
454
+ accepts = parameters.include?([:key, :provider]) || parameters.any? { |type, _| type == :keyrest }
455
+ accepts ? { provider: :apple } : {}
456
+ end
457
+
428
458
  def error_reason(response)
429
459
  apple_error_value(response) || "HTTP #{response.code}"
430
460
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module StandardId
4
4
  module Apple
5
- VERSION = "0.7.0"
5
+ VERSION = "0.9.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_id-apple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
- - Jaryl Sim
7
+ - Rarebit One
8
8
  bindir: bin
9
9
  cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
97
  - !ruby/object:Gem::Version
98
98
  version: '0'
99
99
  requirements: []
100
- rubygems_version: 4.0.10
100
+ rubygems_version: 4.0.20
101
101
  specification_version: 4
102
102
  summary: Apple Sign In provider plugin for the StandardId engine.
103
103
  test_files: []