keycardai-oauth 0.9.1 → 0.10.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: 6d082f18fb1a1d930cd99544d71e2aac6bc2ecb8d6925441cf1edc0ae2ccea71
4
- data.tar.gz: e50e8e4a1927a294bb9bfc37f22e493e110c4d19f37509114fc3bbf692ff5d79
3
+ metadata.gz: fbe4dc737a7a8ab30d17ac738620e62878c16f2f4fa25ad2821cef9d82e635cf
4
+ data.tar.gz: 41f9295086fd2fca1d23c7513d40fb5f689a86ffc3ad2c5c312ec035a38ca2e2
5
5
  SHA512:
6
- metadata.gz: c6b25688f8ca096390ca74317e36e6cb76d4f26eecbd3c8e2f21e4f2553efb10c57d254982e9fb92c66910bffe9acdcbd97d79caa764493fc1f8d4fe6e6004eb
7
- data.tar.gz: 4b176b3d323367a7bceb4f96a5b89f2417454bcc431da20779791a5af9c5629801ab66e1f09f6deb893a20d1e65a6e488f5ec236cc85198165f9b4ead441d408
6
+ metadata.gz: 7166b568c0176d7d9e73b8985c44640d71158f6abf4c3fb5e5d16767b0d4c616c19bd18420a4500de201b20d7ea0a371fc37b23ac9dda50efb3ab2541b0968e2
7
+ data.tar.gz: dbeba673528ec8fbca7e82d82910c3170f133b6e498ca11b87192a384719c5b28ecc04adc4809c7ed24076498f4e3c26e076039707c14e4b3ec03ea03b99565c
data/CHANGELOG.md CHANGED
@@ -15,6 +15,42 @@ 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.10.0-keycardai-oauth (2026-11-25)
19
+
20
+
21
+ - fix(keycardai-oauth)!: reject request client IDs with Basic token exchange (#78)
22
+ - * fix(keycardai-oauth)!: reject request client IDs with Basic token exchange
23
+ - Co-Authored-By: Larry Osakwe <larry@keycard.ai>
24
+ - * test(keycardai-oauth): cover request assertion precedence with workload identity
25
+ - Co-Authored-By: Larry Osakwe <larry@keycard.ai>
26
+ - * fix(keycardai-oauth): keep the Basic client_id guard on the prepared exchange path
27
+ - ---------
28
+ - Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
29
+ Co-authored-by: Larry Osakwe <larry@keycard.ai>
30
+ Co-authored-by: Larry Osakwe <23560354+Larry-Osakwe@users.noreply.github.com>
31
+
32
+ ## 0.9.2-keycardai-oauth (2026-11-25)
33
+
34
+
35
+ - fix(keycardai-oauth): use prepared authentication in token exchange (#77)
36
+ - * fix(keycardai-oauth): use prepared authentication in token exchange
37
+ - Co-Authored-By: Larry Osakwe <larry@keycard.ai>
38
+ - * fix(keycardai-oauth): validate caller-supplied assertion type
39
+ - Co-Authored-By: Larry Osakwe <larry@keycard.ai>
40
+ - ---------
41
+ - Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
42
+ Co-authored-by: Larry Osakwe <larry@keycard.ai>
43
+ - fix(keycardai-oauth): reject explicitly empty verifier audiences (#76)
44
+ - * fix(keycardai-oauth): reject explicitly empty verifier audiences
45
+ - Co-Authored-By: Larry Osakwe <larry@keycard.ai>
46
+ - * docs: refresh bearer conformance example counts
47
+ - Co-Authored-By: Larry Osakwe <larry@keycard.ai>
48
+ - * docs: count only row-numbered conformance examples
49
+ - ---------
50
+ - Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
51
+ Co-authored-by: Larry Osakwe <larry@keycard.ai>
52
+ Co-authored-by: Larry Osakwe <23560354+Larry-Osakwe@users.noreply.github.com>
53
+
18
54
  ## 0.9.1-keycardai-oauth (2026-11-25)
19
55
 
20
56
 
@@ -46,14 +46,17 @@ module Keycardai
46
46
  # delegation; requires actor_token_type
47
47
  # @param actor_token_type [String, nil]
48
48
  # @param client_assertion [String, nil] client-authentication assertion,
49
- # form-encoded in the body
49
+ # form-encoded in the body; requires client_assertion_type
50
50
  # @param client_assertion_type [String, nil]
51
51
  # @param client_id [String, nil] the application credential the
52
- # assertion authenticates as, form-encoded beside client_assertion
52
+ # assertion authenticates as, form-encoded beside client_assertion.
53
+ # When the credential prepares the assertion, its ID replaces this
54
+ # value, or the field is omitted if the credential supplies no ID.
53
55
  # @param issuer [String, nil] per-call zone selection: resolves the zone's
54
56
  # token endpoint and, for a multi-zone credential, that zone's client
55
57
  # authentication. Defaults to the client's issuer.
56
58
  # @return [TokenResponse]
59
+ # @raise [ConfigurationError] when the request sets client_id with HTTP Basic
57
60
  # @raise [OAuthError] an RFC 6749 §5.2 error response (invalid_grant,
58
61
  # invalid_target, invalid_scope, unauthorized_client, ...)
59
62
  # @raise [HTTPError, ProtocolError, NetworkError]
@@ -63,7 +66,8 @@ module Keycardai
63
66
  client_id: nil, issuer: nil)
64
67
  raise ArgumentError, "actor_token_type is required when actor_token is set" if actor_token && !actor_token_type
65
68
 
66
- target = issuer || @issuer
69
+ validate_client_assertion(client_assertion, client_assertion_type)
70
+
67
71
  overrides = {
68
72
  "subject_token_type" => subject_token_type,
69
73
  "resource" => resource,
@@ -76,7 +80,7 @@ module Keycardai
76
80
  "client_assertion_type" => client_assertion_type,
77
81
  "client_id" => client_id
78
82
  }.compact
79
- post_token_request(base_exchange_params(subject_token, target).merge(overrides), issuer: target)
83
+ post_exchange(subject_token, overrides, issuer || @issuer)
80
84
  end
81
85
 
82
86
  # Impersonate a named user: a substitute-user token exchange for
@@ -105,20 +109,37 @@ module Keycardai
105
109
 
106
110
  private
107
111
 
108
- # The base exchange parameters: built by the credential when one is
109
- # configured (it supplies assertion fields and defaults), otherwise the
110
- # bare RFC 8693 defaults. Caller-supplied fields are merged on top.
111
- def base_exchange_params(subject_token, issuer)
112
- if @credential
113
- @credential.prepare_token_exchange_request(subject_token: subject_token,
114
- token_endpoint: token_endpoint(issuer), issuer: issuer)
115
- else
116
- {
117
- "grant_type" => GrantType::TOKEN_EXCHANGE,
118
- "subject_token" => subject_token,
119
- "subject_token_type" => TokenType::ACCESS_TOKEN
120
- }
121
- end
112
+ def validate_client_assertion(assertion, type)
113
+ raise ArgumentError, "client_assertion_type is required when client_assertion is set" if assertion && !type
114
+ end
115
+
116
+ # An explicit client_assertion authenticates the client on its own, so
117
+ # the credential adds no Basic header and prepares no assertion.
118
+ def post_exchange(subject_token, overrides, issuer)
119
+ params = { "grant_type" => GrantType::TOKEN_EXCHANGE, "subject_token" => subject_token,
120
+ "subject_token_type" => TokenType::ACCESS_TOKEN }.merge(overrides)
121
+ return post_token_request(params, issuer: issuer, authorization: nil) if overrides["client_assertion"]
122
+
123
+ authorization = @credential&.authorization_header(issuer: issuer)
124
+ reject_client_id_with_basic(overrides, authorization)
125
+ params = with_assertion(params, issuer) if @credential && !authorization
126
+ post_token_request(params, issuer: issuer, authorization: authorization)
127
+ end
128
+
129
+ # A request client_id never travels beside HTTP Basic: fail before any
130
+ # HTTP request, including discovery.
131
+ def reject_client_id_with_basic(overrides, authorization)
132
+ return unless overrides.key?("client_id") && authorization&.match?(/\ABasic\s/i)
133
+
134
+ raise ConfigurationError, "token exchange client_id cannot be sent with HTTP Basic"
135
+ end
136
+
137
+ def with_assertion(params, issuer)
138
+ prepared = @credential.prepare_token_exchange_request(
139
+ subject_token: params.fetch("subject_token"), resource: params["resource"],
140
+ token_endpoint: token_endpoint(issuer), issuer: issuer
141
+ )
142
+ params.merge(prepared.slice("client_assertion", "client_assertion_type"), "client_id" => prepared["client_id"])
122
143
  end
123
144
  end
124
145
  end
@@ -113,9 +113,8 @@ module Keycardai
113
113
  endpoint
114
114
  end
115
115
 
116
- def post_token_request(params, issuer: @issuer)
116
+ def post_token_request(params, issuer: @issuer, authorization: @credential&.authorization_header(issuer: issuer))
117
117
  headers = { "Accept" => "application/json" }
118
- authorization = @credential&.authorization_header(issuer: issuer)
119
118
  headers["Authorization"] = authorization if authorization
120
119
 
121
120
  response = @http_client.post_form(token_endpoint(issuer), params.compact, headers: headers,
@@ -84,12 +84,13 @@ module Keycardai
84
84
  # @param discovery_ttl [Numeric] jwks_uri cache lifetime in seconds
85
85
  # @param fetch_timeout [Numeric] discovery and JWKS fetch timeout
86
86
  # @param clock [#call] returns the current Time; override in tests
87
- # @raise [ConfigurationError] no trusted issuer
87
+ # @raise [ConfigurationError] no trusted issuer or explicitly empty audiences
88
88
  def initialize(issuers:, audiences: nil, http_client: HTTP::NetHTTPClient.new,
89
89
  key_ttl: JWKSKeyring::DEFAULT_KEY_TTL, discovery_ttl: JWKSKeyring::DEFAULT_DISCOVERY_TTL,
90
90
  fetch_timeout: JWKSKeyring::DEFAULT_FETCH_TIMEOUT, clock: -> { Time.now })
91
91
  @issuers = Array(issuers).reject { |issuer| issuer.nil? || issuer.empty? }
92
92
  raise ConfigurationError, "TokenVerifier requires at least one trusted issuer" if @issuers.empty?
93
+ raise ConfigurationError, "audiences must not be empty" if audiences.is_a?(Array) && audiences.empty?
93
94
 
94
95
  if audiences.nil?
95
96
  warn "Keycardai::OAuth::TokenVerifier has no audiences configured, so it accepts a token minted " \
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Keycardai
4
4
  module OAuth
5
- VERSION = "0.9.1"
5
+ VERSION = "0.10.0"
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.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keycard