keycardai-oauth 0.9.0 → 0.9.2

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: ef60657e21dbad4e33c52dcee7762e64a0e82528e9584fd8fa408e6196ff65ab
4
- data.tar.gz: 9742a4a6082f37ea03ac1eccaa2b60f1d1f9086477980dcb3946e17ce0024bc7
3
+ metadata.gz: 73096603402556204c3aa921c4821cbb250b662d957c6ead112dd28658dd303b
4
+ data.tar.gz: 53a912a76ea3194c4a78273ad494b6cde5e06591bbb429b0a310ea6bd401baa3
5
5
  SHA512:
6
- metadata.gz: 9683da1bb0fbf3e8cadaeef98f4c7b7b29425c011f8b1ef47803f9516544a6bb59f56215c1d8dd4b9aec553ec1ac14c5013076e07a48820ac1288688c0a0bce3
7
- data.tar.gz: '08bb338f8fbd4d2190aaca0a48e9d3669da7928b24642371fc75e540a46325a84561ce01fcd19e80d5bf66e368c6b9e2bc8b848c72d11a0890793322192e28b3'
6
+ metadata.gz: f61479a708c6423eed6139eccedea61332023e16edc1bbacf1424908492db43b5535c85550b700ffdbaf3648e0ad0859406652cfa4abbda3b03ba5925e75952f
7
+ data.tar.gz: 269c4b3ae7318f44b532beaab189352c00e57ebd942b6960ef6c5122f5c1cec0ea828706c0139a39498c3a15358b9764ae45169f1e56c5b4ab1ddbdf41bcae2a
data/CHANGELOG.md CHANGED
@@ -15,6 +15,35 @@ 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.9.2-keycardai-oauth (2026-11-25)
19
+
20
+
21
+ - fix(keycardai-oauth): use prepared authentication in token exchange (#77)
22
+ - * fix(keycardai-oauth): use prepared authentication in token exchange
23
+ - Co-Authored-By: Larry Osakwe <larry@keycard.ai>
24
+ - * fix(keycardai-oauth): validate caller-supplied assertion type
25
+ - Co-Authored-By: Larry Osakwe <larry@keycard.ai>
26
+ - ---------
27
+ - Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
28
+ Co-authored-by: Larry Osakwe <larry@keycard.ai>
29
+ - fix(keycardai-oauth): reject explicitly empty verifier audiences (#76)
30
+ - * fix(keycardai-oauth): reject explicitly empty verifier audiences
31
+ - Co-Authored-By: Larry Osakwe <larry@keycard.ai>
32
+ - * docs: refresh bearer conformance example counts
33
+ - Co-Authored-By: Larry Osakwe <larry@keycard.ai>
34
+ - * docs: count only row-numbered conformance examples
35
+ - ---------
36
+ - Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
37
+ Co-authored-by: Larry Osakwe <larry@keycard.ai>
38
+ Co-authored-by: Larry Osakwe <23560354+Larry-Osakwe@users.noreply.github.com>
39
+
40
+ ## 0.9.1-keycardai-oauth (2026-11-25)
41
+
42
+
43
+ - fix(keycardai-oauth): normalize the verified caller audience (#75)
44
+ - Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
45
+ Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
46
+
18
47
  ## 0.9.0-keycardai-oauth (2026-11-25)
19
48
 
20
49
 
@@ -46,10 +46,12 @@ 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.
@@ -63,7 +65,8 @@ module Keycardai
63
65
  client_id: nil, issuer: nil)
64
66
  raise ArgumentError, "actor_token_type is required when actor_token is set" if actor_token && !actor_token_type
65
67
 
66
- target = issuer || @issuer
68
+ validate_client_assertion(client_assertion, client_assertion_type)
69
+
67
70
  overrides = {
68
71
  "subject_token_type" => subject_token_type,
69
72
  "resource" => resource,
@@ -76,7 +79,7 @@ module Keycardai
76
79
  "client_assertion_type" => client_assertion_type,
77
80
  "client_id" => client_id
78
81
  }.compact
79
- post_token_request(base_exchange_params(subject_token, target).merge(overrides), issuer: target)
82
+ post_exchange(subject_token, overrides, issuer || @issuer)
80
83
  end
81
84
 
82
85
  # Impersonate a named user: a substitute-user token exchange for
@@ -105,20 +108,24 @@ module Keycardai
105
108
 
106
109
  private
107
110
 
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
111
+ def validate_client_assertion(assertion, type)
112
+ raise ArgumentError, "client_assertion_type is required when client_assertion is set" if assertion && !type
113
+ end
114
+
115
+ def post_exchange(subject_token, overrides, issuer)
116
+ params = { "grant_type" => GrantType::TOKEN_EXCHANGE, "subject_token" => subject_token,
117
+ "subject_token_type" => TokenType::ACCESS_TOKEN }.merge(overrides)
118
+ authorization = @credential&.authorization_header(issuer: issuer)
119
+ params = with_assertion(params, issuer) if @credential && !authorization && !overrides["client_assertion"]
120
+ post_token_request(params, issuer: issuer, authorization: authorization)
121
+ end
122
+
123
+ def with_assertion(params, issuer)
124
+ prepared = @credential.prepare_token_exchange_request(
125
+ subject_token: params.fetch("subject_token"), resource: params["resource"],
126
+ token_endpoint: token_endpoint(issuer), issuer: issuer
127
+ )
128
+ params.merge(prepared.slice("client_assertion", "client_assertion_type"), "client_id" => prepared["client_id"])
122
129
  end
123
130
  end
124
131
  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 " \
@@ -138,6 +139,8 @@ module Keycardai
138
139
  def verify_against(issuers, token)
139
140
  claims = JWTVerifier.new(issuers: issuers, keyring: @keyring, audiences: @audiences,
140
141
  clock: @clock).verify(token)
142
+ audience = claims["aud"]
143
+ claims = claims.merge("aud" => [audience]) if audience.is_a?(String)
141
144
  AccessToken.new(token: token, claims: claims)
142
145
  end
143
146
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Keycardai
4
4
  module OAuth
5
- VERSION = "0.9.0"
5
+ VERSION = "0.9.2"
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.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keycard