keycardai-oauth 0.14.0 → 0.15.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: fc9efe8a3b93bb81137cfb6829e5461ac369ccb9334dd7aca57e058263802b2f
4
- data.tar.gz: 4e11001bf77f8c69a2ab4fa8066c204adeeb74edcc986f8d260717dd6d5d6fd4
3
+ metadata.gz: 2270af78d15b4eaffa12e3f66d5f7ad750705a4b9e09c38a0473a49b358f7271
4
+ data.tar.gz: d036adb9c1c73b34e7ad1a30c03603781a2a55ea32cdc2606dd6c059b407d6d9
5
5
  SHA512:
6
- metadata.gz: e8b6eea8644d3f8d38c1520aca1152b5a4a7ffadf7c1c0df631e846954ee19d03a599cd315644c0792d64cf43d853c5770ba2eed7ce1c1e6f1147d13e6ff8150
7
- data.tar.gz: 29e30c8a5deefa76102b3fd2f9a6a75877fe4ffa8de18e772f29b59b2a30c568aed103f928db6504c9512de140918257b337104518bf9c8170d58db26f3ea18a
6
+ metadata.gz: 9f3c50b35c045bbada1c713da736e9746d1b4d720b0cbb9ba3c8c498952617e1b1b6d91d7aca4710d0f58fd2fb7b1c83142eb46203ed09000a6c59886fd0a240
7
+ data.tar.gz: b023b385d517a4a4155763e656b0cb6614e307ce6d0df3836704a33b1dced3f3a2dd5cfe63fab14a52fd52499b960ddf29583e8aa900321d44d289ae7caaaac3
data/CHANGELOG.md CHANGED
@@ -15,6 +15,19 @@ 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.15.0-keycardai-oauth (2026-11-26)
19
+
20
+
21
+ - feat(keycardai-oauth): bind credentials to the client credentials grant (#103)
22
+ - * feat(keycardai-oauth): bind credentials to the client credentials grant
23
+ - Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
24
+ - * test(keycardai-oauth): cover row 4d without a request client_id
25
+ - * fix(keycardai-oauth): reject request client fields beside a configured assertion credential and resolve ClientSecret before discovery
26
+ - ---------
27
+ - Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
28
+ Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
29
+ Co-authored-by: Larry Osakwe <23560354+Larry-Osakwe@users.noreply.github.com>
30
+
18
31
  ## 0.14.0-keycardai-oauth (2026-11-26)
19
32
 
20
33
 
data/README.md CHANGED
@@ -14,7 +14,7 @@ bundle add keycardai-oauth
14
14
  Capabilities:
15
15
 
16
16
  - Token exchange and impersonation (RFC 8693)
17
- - Client credentials grant (RFC 6749 §4.4)
17
+ - Client credentials grant (RFC 6749 §4.4), with an application credential bound on `ClientCredentialsClient`
18
18
  - Authorization code + PKCE, including the challenge-driven loopback flow (RFC 8252)
19
19
  - Device authorization grant (RFC 8628)
20
20
  - Token revocation (RFC 7009)
@@ -14,9 +14,8 @@ module Keycardai
14
14
  include TokenRequests
15
15
 
16
16
  # @param issuer [String] the zone's issuer URL
17
- # @param credential [Object, nil] a Basic-auth credential (ClientSecret);
18
- # exclusive with client_id/client_secret. Assertion-based credentials
19
- # supply their assertion through the request fields instead.
17
+ # @param credential [Object, nil] provides client authentication;
18
+ # exclusive with client_id/client_secret
20
19
  # @param client_id [String, nil] shared-secret client id (HTTP Basic)
21
20
  # @param client_secret [String, nil] shared-secret client secret;
22
21
  # provide both or neither
@@ -39,7 +38,7 @@ module Keycardai
39
38
  # @param scope [String, nil] space-separated scopes for the token
40
39
  # @param resource [String, nil] RFC 8707 resource indicator
41
40
  # @param client_assertion [String, nil] client-authentication assertion,
42
- # form-encoded in the body
41
+ # form-encoded in the body in place of configured client authentication
43
42
  # @param client_assertion_type [String, nil]
44
43
  # @param client_id [String, nil] the application credential the
45
44
  # assertion authenticates as, form-encoded beside client_assertion;
@@ -50,12 +49,7 @@ module Keycardai
50
49
  # @raise [HTTPError, ProtocolError, NetworkError]
51
50
  def request_token(scope: nil, resource: nil, client_assertion: nil, client_assertion_type: nil,
52
51
  client_id: nil, issuer: nil)
53
- target = issuer || @issuer
54
- if client_id && @credential&.authorization_header(issuer: target)
55
- raise ConfigurationError, "client_id is sent beside client_assertion, not with HTTP Basic"
56
- end
57
-
58
- post_token_request(
52
+ post_credentials(
59
53
  {
60
54
  "grant_type" => GrantType::CLIENT_CREDENTIALS,
61
55
  "scope" => scope,
@@ -64,9 +58,52 @@ module Keycardai
64
58
  "client_assertion_type" => client_assertion_type,
65
59
  "client_id" => client_id
66
60
  },
67
- issuer: target
61
+ issuer || @issuer
68
62
  )
69
63
  end
64
+
65
+ private
66
+
67
+ def post_credentials(params, issuer)
68
+ if params["client_assertion"] || !@credential
69
+ return post_token_request(params, issuer: issuer, authorization: nil)
70
+ end
71
+ # A ClientSecret resolves its Basic header without the token endpoint,
72
+ # so an unconfigured zone fails before any discovery request.
73
+ if @credential.is_a?(ClientSecret) || !@credential.respond_to?(:client_authentication)
74
+ return post_with_header(params, issuer)
75
+ end
76
+
77
+ post_authenticated_credentials(params, issuer)
78
+ end
79
+
80
+ def post_authenticated_credentials(params, issuer)
81
+ reject_request_client_fields(params)
82
+ endpoint = token_endpoint(issuer)
83
+ auth = @credential.client_authentication(issuer: issuer, endpoint: endpoint)
84
+ form = params.merge(auth.params)
85
+ post_token_form(endpoint, form, { "Accept" => "application/json" }.merge(auth.headers))
86
+ end
87
+
88
+ def post_with_header(params, issuer)
89
+ authorization = @credential.authorization_header(issuer: issuer)
90
+ reject_body_client_id(params) if authorization
91
+ post_token_request(params, issuer: issuer, authorization: authorization)
92
+ end
93
+
94
+ def reject_body_client_id(params)
95
+ return unless params["client_id"]
96
+
97
+ raise ConfigurationError, "client_id is sent beside client_assertion, not with HTTP Basic"
98
+ end
99
+
100
+ # The configured credential supplies client_id and client_assertion_type,
101
+ # so a request value would be dropped or overridden: fail instead.
102
+ def reject_request_client_fields(params)
103
+ return unless params["client_id"] || params["client_assertion_type"]
104
+
105
+ raise ConfigurationError, "client_id and client_assertion_type are sent only beside a request client_assertion"
106
+ end
70
107
  end
71
108
  end
72
109
  end
@@ -125,9 +125,11 @@ module Keycardai
125
125
  def post_token_request(params, issuer: @issuer, authorization: @credential&.authorization_header(issuer: issuer))
126
126
  headers = { "Accept" => "application/json" }
127
127
  headers["Authorization"] = authorization if authorization
128
+ post_token_form(token_endpoint(issuer), params, headers)
129
+ end
128
130
 
129
- response = @http_client.post_form(token_endpoint(issuer), params.compact, headers: headers,
130
- timeout: @timeout)
131
+ def post_token_form(endpoint, params, headers)
132
+ response = @http_client.post_form(endpoint, params.compact, headers: headers, timeout: @timeout)
131
133
  TokenRequests.parse_response(response)
132
134
  end
133
135
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Keycardai
4
4
  module OAuth
5
- VERSION = "0.14.0"
5
+ VERSION = "0.15.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.14.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Keycard