keycardai-oauth 0.7.1 → 0.8.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: 1ffd084e2ae559bd7d4cb10acd883e13b81ccaf301348ff89a7b412aaedaf540
4
- data.tar.gz: 7e8cc6b15aecffd015acf9ded6727abb83e2aa87cd35522c2e7694bc8414b82d
3
+ metadata.gz: 9b06d9181e8d3dfbae0c141bcc8b4ffd4850f49f247fd3115ac3b8aa2a745920
4
+ data.tar.gz: 2b698ca8fa9dd2f0d002148aa3d54698fd48a43b2666356b358d5db749ea5402
5
5
  SHA512:
6
- metadata.gz: 10d0e36beca8ca688172e01ecdf7fdb1131ecd44acfad1e6634c2f71f77458f9d31f7aeeec5f19f25f9dce03198662f111c023e5c8e76eb11728d4054d9f0a2c
7
- data.tar.gz: c663311fbc07ac0a8880f8197c3371483e177c61a70d531ddbe9c125e51eb3e6c2ebca7807267250207c93e35b068f2e225f31549711f6989052751dba81368d
6
+ metadata.gz: 36a13be3a6755509270f5aa88d06ea093a31c9c3191c66c85c6249829d56d0672d0e4d454ca738c5d2d00318d927055d2bb5fd280391fc622f2e9cd329e24441
7
+ data.tar.gz: ebeb9a7e16fd639899d677ebd00d83f987a8993d68d02be5e1eefdcd1abc60c8d53b1d4e4c51d19f4c635136e54847bc6c5533c22842b5a81d777ce3c0981b04
data/CHANGELOG.md CHANGED
@@ -15,6 +15,33 @@ the loopback flow (RFC 8252), JWT signing and verification with a caching JWKS
15
15
  keyring, the three application credentials (ClientSecret with multi-zone,
16
16
  WebIdentity, WorkloadIdentity with pluggable token sources), and AccessContext.
17
17
 
18
+ ## 0.8.1-keycardai-oauth (2026-11-25)
19
+
20
+
21
+ - fix(keycardai-oauth): merge and deduplicate authorize URL queries (#72)
22
+ - Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
23
+ Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
24
+
25
+ ## 0.8.0-keycardai-oauth (2026-11-23)
26
+
27
+
28
+ - fix(keycardai-oauth)!: require an issuer allow-list before sending client auth to a challenge-resolved issuer (#63)
29
+ - * fix(keycardai-oauth): require allowed_issuers before sending client auth to a challenge-resolved issuer
30
+ - authenticate_from_challenge takes the issuer from the protected resource's
31
+ metadata. With client_secret set it now requires allowed_issuers and
32
+ checks the resolved issuer against it before any request to that
33
+ issuer. SDK-120.
34
+ - * fix(keycardai-oauth): use a multi-zone ClientSecret's zone issuers as the challenge allow-list
35
+ - When allowed_issuers is unset and the credential is a multi-zone
36
+ ClientSecret, authenticate_from_challenge checks the resolved issuer
37
+ against the credential's zone issuers. An explicit allowed_issuers wins.
38
+ SDK-120.
39
+ - * fix(keycardai-oauth): validate challenge issuer allow-list entries
40
+ - Co-Authored-By: Larry Osakwe <larry@keycard.ai>
41
+ - ---------
42
+ - Co-authored-by: Larry Osakwe <larry@keycard.ai>
43
+ Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
44
+
18
45
  ## 0.7.1-keycardai-oauth (2026-11-23)
19
46
 
20
47
 
@@ -102,19 +102,68 @@ module Keycardai
102
102
  # Challenge-driven entry to the login flow: resolve the issuer from a
103
103
  # WWW-Authenticate challenge, then run authenticate against it.
104
104
  #
105
+ # The protected resource names the issuer, so client authentication
106
+ # (client_secret or credential) requires an allow-list. A multi-zone
107
+ # ClientSecret credential counts as the pin: with allowed_issuers unset
108
+ # or empty, its zone issuers are the allow-list.
109
+ # The resolved issuer must equal one of them, compared without a
110
+ # trailing slash. A public client may omit the list; when it sets one,
111
+ # it is enforced the same way.
112
+ #
105
113
  # @param www_authenticate [String] the WWW-Authenticate header value
114
+ # @param allowed_issuers [Array<String>, nil] the issuers the caller
115
+ # trusts; overrides a multi-zone ClientSecret's zone issuers
106
116
  # @param options [Hash] forwarded to authenticate
107
117
  # @return [TokenResponse]
108
- def self.authenticate_from_challenge(www_authenticate, http_client: HTTP::NetHTTPClient.new, **options)
118
+ # @raise [ConfigurationError] invalid credential, an allowed_issuers entry
119
+ # that is not a non-empty String, or client authentication without an
120
+ # allow-list, before any request; or a resolved issuer outside the
121
+ # allow-list, after the resource metadata fetch and before any request
122
+ # to that issuer
123
+ def self.authenticate_from_challenge(www_authenticate, http_client: HTTP::NetHTTPClient.new,
124
+ allowed_issuers: nil, **options)
109
125
  # Credential errors surface before the resource metadata fetch.
110
126
  if options[:credential]
111
127
  ClientAuth.validate(credential: options[:credential], client_id: nil, client_secret: options[:client_secret])
112
128
  end
129
+ allowed, source = challenge_allow_list(allowed_issuers, options[:credential])
130
+ client_auth = !options[:client_secret].to_s.empty? || !options[:credential].nil?
131
+ if client_auth && allowed.empty?
132
+ raise ConfigurationError,
133
+ "pass allowed_issuers to send client_secret or credential to an issuer resolved from a challenge"
134
+ end
135
+
113
136
  issuer = resolve_issuer_from_challenge(www_authenticate, http_client: http_client,
114
137
  timeout: options[:timeout])
138
+ check_challenge_issuer(issuer, allowed, source)
115
139
  authenticate(issuer: issuer, http_client: http_client, **options)
116
140
  end
117
141
 
142
+ # Raises unless issuer is in a non-empty allowed, compared without a
143
+ # trailing slash. An empty list allows any issuer (a public client).
144
+ def self.check_challenge_issuer(issuer, allowed, source)
145
+ return if allowed.empty? || allowed.any? { |a| a.chomp("/") == issuer.chomp("/") }
146
+
147
+ raise ConfigurationError, "the challenge resolved issuer #{issuer}, which is not in #{source}"
148
+ end
149
+ private_class_method :check_challenge_issuer
150
+
151
+ # The allow-list for a challenge entry and how to name it in an error:
152
+ # allowed_issuers when set, else a multi-zone ClientSecret's zone issuers.
153
+ def self.challenge_allow_list(allowed_issuers, credential)
154
+ allowed = Array(allowed_issuers)
155
+ unless allowed.all? { |entry| entry.is_a?(String) && !entry.empty? }
156
+ raise ConfigurationError, "allowed_issuers entries must be non-empty strings"
157
+ end
158
+
159
+ return [allowed, "allowed_issuers"] unless allowed.empty?
160
+ return [credential.issuers, "the multi-zone ClientSecret's zone issuers"] if
161
+ credential.is_a?(ClientSecret) && credential.multi_zone?
162
+
163
+ [[], "allowed_issuers"]
164
+ end
165
+ private_class_method :challenge_allow_list
166
+
118
167
  # Internals of the loopback flow. Not public API.
119
168
  module Loopback
120
169
  SUCCESS_PAGE = "<html><body><p>Authentication complete. You can close this window.</p></body></html>"
@@ -15,7 +15,7 @@ module Keycardai
15
15
  # @param code_challenge_method [String] the method the challenge was derived with
16
16
  # @param scope [String, nil] space-separated scopes
17
17
  # @param state [String, nil] CSRF state value
18
- # @param resources [Array<String>] RFC 8707 resource indicators; each entry
18
+ # @param resources [Array<String>] RFC 8707 resource indicators; each distinct value
19
19
  # becomes its own resource parameter, and the authorization server binds
20
20
  # them into the authorization code at authorize time
21
21
  # @return [String] the authorize URL
@@ -32,11 +32,18 @@ module Keycardai
32
32
  }.compact
33
33
 
34
34
  uri = URI(authorization_endpoint)
35
- query = URI.encode_www_form(params.to_a + Array(resources).map { |resource| ["resource", resource] })
36
- uri.query = uri.query.nil? || uri.query.empty? ? query : "#{uri.query}&#{query}"
35
+ sdk_params = params.to_a + Array(resources).uniq.map { |resource| ["resource", resource] }
36
+ uri.query = merge_authorize_query(uri.query, sdk_params)
37
37
  uri.to_s
38
38
  end
39
39
 
40
+ def self.merge_authorize_query(query, sdk_params)
41
+ sdk_keys = sdk_params.map(&:first)
42
+ inherited = URI.decode_www_form(query.to_s).reject { |pair| sdk_keys.include?(pair.first) }
43
+ URI.encode_www_form(inherited + sdk_params)
44
+ end
45
+ private_class_method :merge_authorize_query
46
+
40
47
  # Exchange an authorization code for a token (RFC 6749 §4.1.3). A public
41
48
  # client sends its client_id in the body. A confidential client
42
49
  # authenticates with HTTP Basic and omits client_id from the body. A
@@ -47,7 +47,11 @@ module Keycardai
47
47
  !@pairs.nil?
48
48
  end
49
49
 
50
- # @return [Array<String>] the issuer URLs this credential can serve
50
+ # The issuer URLs this credential can serve, without a trailing slash.
51
+ # authenticate_from_challenge uses a multi-zone credential's issuers as
52
+ # its allow-list when allowed_issuers is unset.
53
+ #
54
+ # @return [Array<String>] the zone issuers; empty for a single zone
51
55
  def issuers
52
56
  multi_zone? ? @pairs.keys : []
53
57
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Keycardai
4
4
  module OAuth
5
- VERSION = "0.7.1"
5
+ VERSION = "0.8.1"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keycardai-oauth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.1
4
+ version: 0.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keycard