keycardai-oauth 0.11.3 → 0.12.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 +4 -4
- data/CHANGELOG.md +25 -0
- data/README.md +20 -0
- data/lib/keycardai/oauth/discovery.rb +3 -1
- data/lib/keycardai/oauth/errors.rb +20 -4
- data/lib/keycardai/oauth/http.rb +2 -1
- data/lib/keycardai/oauth/metadata_retry.rb +7 -3
- data/lib/keycardai/oauth/token_revocation.rb +75 -0
- data/lib/keycardai/oauth/version.rb +1 -1
- data/lib/keycardai/oauth/web_identity.rb +3 -4
- data/lib/keycardai/oauth.rb +1 -0
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7ccdb651e530f4a1ad780531eef59ed0d02f30a96bebb4104f9010ea4f784b24
|
|
4
|
+
data.tar.gz: 8942a274d0a490f8faadb19348b547b74f09f03ba90252d2bc3ee77e12715dd1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8d6292413c8a8efbf361a3bbed96ebdfb22f53a60cd27b367a16b234cfbd7872a2f2401091ba4acfe97633b0658939c600158a829dc4c3bf880323706f374415
|
|
7
|
+
data.tar.gz: 4e788c4f977841dea9409c7001e79d64cc2fa340a48ffa7e4c01ca24c076423a09c1005038859de39107d269234df78017bffc89ee1aca8b0c41800cb7893612
|
data/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,31 @@ 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.12.0-keycardai-oauth (2026-11-25)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
- feat(keycardai-oauth): token revocation (ID-881) (#97)
|
|
22
|
+
- * feat(keycardai-oauth): token revocation (ID-881)
|
|
23
|
+
- Co-Authored-By: Larry Osakwe <larry@keycard.ai>
|
|
24
|
+
- * docs: record token revocation conformance
|
|
25
|
+
- Co-Authored-By: Larry Osakwe <larry@keycard.ai>
|
|
26
|
+
- * fix(keycardai-oauth): require HTTPS revocation discovery
|
|
27
|
+
- Co-Authored-By: Larry Osakwe <larry@keycard.ai>
|
|
28
|
+
- * fix(keycardai-oauth): use the discovered revocation issuer
|
|
29
|
+
- Co-Authored-By: Larry Osakwe <larry@keycard.ai>
|
|
30
|
+
- * fix(keycardai-oauth): use supplied metadata for revocation audience
|
|
31
|
+
- Co-Authored-By: Larry Osakwe <larry@keycard.ai>
|
|
32
|
+
- ---------
|
|
33
|
+
- Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
|
|
34
|
+
Co-authored-by: Larry Osakwe <larry@keycard.ai>
|
|
35
|
+
|
|
36
|
+
## 0.11.4-keycardai-oauth (2026-11-25)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
- fix(keycardai-oauth): pace oversized 5xx metadata responses (#92)
|
|
40
|
+
- Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
|
|
41
|
+
Co-authored-by: Larry Osakwe <larry@keycard.ai>
|
|
42
|
+
|
|
18
43
|
## 0.11.3-keycardai-oauth (2026-11-25)
|
|
19
44
|
|
|
20
45
|
|
data/README.md
CHANGED
|
@@ -17,6 +17,7 @@ Capabilities:
|
|
|
17
17
|
- Client credentials grant (RFC 6749 §4.4)
|
|
18
18
|
- Authorization code + PKCE, including the challenge-driven loopback flow (RFC 8252)
|
|
19
19
|
- Device authorization grant (RFC 8628)
|
|
20
|
+
- Token revocation (RFC 7009)
|
|
20
21
|
- Dynamic client registration (RFC 7591)
|
|
21
22
|
- Authorization server discovery (RFC 8414), including the OIDC Discovery 1.0 §3 endpoints
|
|
22
23
|
- UserInfo: the signed-in user's identity claims (OIDC Core 1.0 §5.3)
|
|
@@ -132,6 +133,25 @@ credential) for refresh, the code exchange, `authenticate` and device
|
|
|
132
133
|
authorization; without it these raise `ConfigurationError` before any request.
|
|
133
134
|
A credential of your own must respond to `client_authentication`.
|
|
134
135
|
|
|
136
|
+
### Revoke a token
|
|
137
|
+
|
|
138
|
+
Revoking a Keycard refresh token revokes its session. Use the same client
|
|
139
|
+
authentication as for refresh: a public client ID, client ID and secret, or
|
|
140
|
+
`credential:`.
|
|
141
|
+
|
|
142
|
+
```ruby
|
|
143
|
+
Keycardai::OAuth.revoke_token(
|
|
144
|
+
"https://your-zone.keycard.cloud",
|
|
145
|
+
token: stored_refresh_token,
|
|
146
|
+
client_id: ENV.fetch("KEYCARD_CLIENT_ID"),
|
|
147
|
+
client_secret: ENV["KEYCARD_CLIENT_SECRET"], # omit for a public client
|
|
148
|
+
)
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Pass `metadata:` to reuse discovery results. The server must advertise a
|
|
152
|
+
`revocation_endpoint`. The operation returns `nil` on HTTP 200, even for
|
|
153
|
+
unknown, expired, or already revoked tokens. It does not retry.
|
|
154
|
+
|
|
135
155
|
### Sign in a device with no browser
|
|
136
156
|
|
|
137
157
|
The device authorization grant (RFC 8628) gets a token for a person on a
|
|
@@ -16,6 +16,7 @@ module Keycardai
|
|
|
16
16
|
AuthorizationServerMetadata = Data.define(
|
|
17
17
|
:issuer, :token_endpoint, :authorization_endpoint, :jwks_uri, :registration_endpoint,
|
|
18
18
|
:userinfo_endpoint, :end_session_endpoint, :device_authorization_endpoint,
|
|
19
|
+
:revocation_endpoint, :revocation_endpoint_auth_methods_supported,
|
|
19
20
|
:grant_types_supported, :token_endpoint_auth_methods_supported, :response_types_supported, :raw
|
|
20
21
|
) do
|
|
21
22
|
# Every member but +issuer+ defaults to nil, and +raw+ to an empty
|
|
@@ -23,7 +24,8 @@ module Keycardai
|
|
|
23
24
|
# knows.
|
|
24
25
|
def initialize(issuer:, token_endpoint: nil, authorization_endpoint: nil, jwks_uri: nil,
|
|
25
26
|
registration_endpoint: nil, userinfo_endpoint: nil, end_session_endpoint: nil,
|
|
26
|
-
device_authorization_endpoint: nil,
|
|
27
|
+
device_authorization_endpoint: nil, revocation_endpoint: nil,
|
|
28
|
+
revocation_endpoint_auth_methods_supported: nil, grant_types_supported: nil,
|
|
27
29
|
token_endpoint_auth_methods_supported: nil, response_types_supported: nil, raw: {})
|
|
28
30
|
super
|
|
29
31
|
end
|
|
@@ -8,11 +8,19 @@ module Keycardai
|
|
|
8
8
|
module OAuth
|
|
9
9
|
# Invalid configuration detected at construction time: missing credential,
|
|
10
10
|
# empty issuer list, an algorithm the verifier does not implement.
|
|
11
|
-
class ConfigurationError < Keycardai::Error
|
|
11
|
+
class ConfigurationError < Keycardai::Error
|
|
12
|
+
def retryable?
|
|
13
|
+
false
|
|
14
|
+
end
|
|
15
|
+
end
|
|
12
16
|
|
|
13
17
|
# A transport-level failure (DNS, TLS, timeout) wrapping the underlying
|
|
14
18
|
# exception as +cause+.
|
|
15
|
-
class NetworkError < Keycardai::Error
|
|
19
|
+
class NetworkError < Keycardai::Error
|
|
20
|
+
def retryable?
|
|
21
|
+
true
|
|
22
|
+
end
|
|
23
|
+
end
|
|
16
24
|
|
|
17
25
|
# A non-2xx HTTP response. Has the status code and response body.
|
|
18
26
|
class HTTPError < Keycardai::Error
|
|
@@ -28,6 +36,11 @@ module Keycardai
|
|
|
28
36
|
@body = body
|
|
29
37
|
@retry_after = retry_after
|
|
30
38
|
end
|
|
39
|
+
|
|
40
|
+
# @return [Boolean] whether repeating the request unchanged could succeed
|
|
41
|
+
def retryable?
|
|
42
|
+
status == 429 || (500..599).cover?(status)
|
|
43
|
+
end
|
|
31
44
|
end
|
|
32
45
|
|
|
33
46
|
# An OAuth error response from the authorization server (RFC 6749 §5.2).
|
|
@@ -54,7 +67,7 @@ module Keycardai
|
|
|
54
67
|
|
|
55
68
|
# @return [Boolean] whether repeating the request unchanged could succeed
|
|
56
69
|
def retryable?
|
|
57
|
-
|
|
70
|
+
super || !PERMANENT_ERROR_CODES.include?(error)
|
|
58
71
|
end
|
|
59
72
|
end
|
|
60
73
|
|
|
@@ -117,9 +130,12 @@ module Keycardai
|
|
|
117
130
|
class ResponseBodyTooLargeError < ProtocolError
|
|
118
131
|
# @return [Integer]
|
|
119
132
|
attr_reader :limit
|
|
133
|
+
# @return [String, nil]
|
|
134
|
+
attr_reader :retry_after
|
|
120
135
|
|
|
121
|
-
def initialize(status:, limit: MAX_RESPONSE_BODY_BYTES)
|
|
136
|
+
def initialize(status:, limit: MAX_RESPONSE_BODY_BYTES, retry_after: nil)
|
|
122
137
|
@limit = limit
|
|
138
|
+
@retry_after = retry_after
|
|
123
139
|
super("response body exceeded the #{limit}-byte decoded size limit (HTTP #{status})",
|
|
124
140
|
code: "invalid_response", status: status)
|
|
125
141
|
end
|
data/lib/keycardai/oauth/http.rb
CHANGED
|
@@ -179,7 +179,8 @@ module Keycardai
|
|
|
179
179
|
def check_limit(size, response, limit)
|
|
180
180
|
return if limit.nil? || size <= limit
|
|
181
181
|
|
|
182
|
-
raise ResponseBodyTooLargeError.new(status: response.code.to_i, limit: limit
|
|
182
|
+
raise ResponseBodyTooLargeError.new(status: response.code.to_i, limit: limit,
|
|
183
|
+
retry_after: response.get_fields("Retry-After")&.first)
|
|
183
184
|
end
|
|
184
185
|
end
|
|
185
186
|
private_constant :BoundedBodyReader
|
|
@@ -20,7 +20,11 @@ module Keycardai
|
|
|
20
20
|
return !(cause.is_a?(OpenSSL::SSL::SSLError) && cause.message.include?("certificate verify failed"))
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
response_error?(error) && (error.status == 429 || (500..599).cover?(error.status))
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.response_error?(error)
|
|
27
|
+
error.is_a?(HTTPError) || error.is_a?(ResponseBodyTooLargeError)
|
|
24
28
|
end
|
|
25
29
|
|
|
26
30
|
def initialize(clock, monotonic_clock: clock.equal?(WALL_CLOCK) ? MONOTONIC_CLOCK : clock)
|
|
@@ -88,11 +92,11 @@ module Keycardai
|
|
|
88
92
|
end
|
|
89
93
|
|
|
90
94
|
def throttled?(error)
|
|
91
|
-
|
|
95
|
+
self.class.response_error?(error) && error.status == 429
|
|
92
96
|
end
|
|
93
97
|
|
|
94
98
|
def retry_after(error)
|
|
95
|
-
return unless
|
|
99
|
+
return unless self.class.response_error?(error) && [429, 503].include?(error.status)
|
|
96
100
|
|
|
97
101
|
header = error.retry_after.to_s.strip
|
|
98
102
|
return [60, header.to_i].min if /\A[0-9]+\z/.match?(header)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module Keycardai
|
|
6
|
+
# Token revocation (RFC 7009).
|
|
7
|
+
module OAuth
|
|
8
|
+
# Revoke a token (RFC 7009). A Keycard refresh token revokes its session.
|
|
9
|
+
# HTTP 200 succeeds without a response body, including for unknown,
|
|
10
|
+
# expired, invalid, or already revoked tokens.
|
|
11
|
+
#
|
|
12
|
+
# @param issuer [String, nil] the zone issuer URL; HTTPS is required for discovery
|
|
13
|
+
# @param metadata [AuthorizationServerMetadata, nil] pre-discovered metadata
|
|
14
|
+
# @param token [String] the token to revoke
|
|
15
|
+
# @param token_type_hint [String] the hint sent to the revocation endpoint
|
|
16
|
+
# @param client_id [String, nil] required unless credential is set
|
|
17
|
+
# @param client_secret [String, nil] use HTTP Basic with client_id
|
|
18
|
+
# @param credential [#client_authentication, nil] authenticates in place of client_id and client_secret
|
|
19
|
+
# @param http_client [#get, #post_form] pluggable transport
|
|
20
|
+
# @param timeout [Numeric, nil] request timeout in seconds
|
|
21
|
+
# @return [nil]
|
|
22
|
+
# @raise [ConfigurationError] invalid inputs or missing or invalid revocation endpoint
|
|
23
|
+
# @raise [OAuthError, HTTPError, ProtocolError, NetworkError]
|
|
24
|
+
def self.revoke_token(issuer = nil, token: nil, metadata: nil, client_id: nil, client_secret: nil,
|
|
25
|
+
credential: nil, token_type_hint: "refresh_token", http_client: HTTP::NetHTTPClient.new,
|
|
26
|
+
timeout: nil)
|
|
27
|
+
raise ConfigurationError, "token must be a non-empty string" unless token.is_a?(String) && !token.empty?
|
|
28
|
+
|
|
29
|
+
ClientAuth.validate(credential: credential, client_id: client_id, client_secret: client_secret)
|
|
30
|
+
metadata, issuer = resolve_revocation_metadata(issuer, metadata, http_client: http_client, timeout: timeout)
|
|
31
|
+
endpoint = require_revocation_https(metadata.revocation_endpoint, "revocation_endpoint")
|
|
32
|
+
params = [["token", token], ["token_type_hint", token_type_hint]]
|
|
33
|
+
params, headers = ClientAuth.apply(params, { "Accept" => "application/json" },
|
|
34
|
+
issuer: issuer, endpoint: metadata.issuer, credential: credential,
|
|
35
|
+
client_id: client_id, client_secret: client_secret)
|
|
36
|
+
response = http_client.post_form(endpoint, params, headers: headers, timeout: timeout)
|
|
37
|
+
raise TokenRequests.error_for(response, endpoint_name: "revocation endpoint") unless response.status == 200
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def self.revocation_issuer(issuer, metadata)
|
|
41
|
+
zone = issuer || metadata&.issuer
|
|
42
|
+
raise ConfigurationError, "provide an issuer or metadata" unless zone.is_a?(String) && !zone.empty?
|
|
43
|
+
return zone unless metadata
|
|
44
|
+
return zone if same_revocation_issuer?(zone, metadata.issuer)
|
|
45
|
+
|
|
46
|
+
raise ConfigurationError, "issuer does not match the metadata issuer"
|
|
47
|
+
end
|
|
48
|
+
private_class_method :revocation_issuer
|
|
49
|
+
|
|
50
|
+
def self.same_revocation_issuer?(zone, discovered)
|
|
51
|
+
discovered.is_a?(String) && zone.chomp("/") == discovered.chomp("/")
|
|
52
|
+
end
|
|
53
|
+
private_class_method :same_revocation_issuer?
|
|
54
|
+
|
|
55
|
+
def self.resolve_revocation_metadata(issuer, metadata, http_client:, timeout:)
|
|
56
|
+
issuer = revocation_issuer(issuer, metadata)
|
|
57
|
+
return [metadata, issuer] if metadata
|
|
58
|
+
|
|
59
|
+
require_revocation_https(issuer, "issuer")
|
|
60
|
+
discovered = fetch_authorization_server_metadata(issuer, http_client: http_client, timeout: timeout)
|
|
61
|
+
[discovered, discovered.issuer]
|
|
62
|
+
end
|
|
63
|
+
private_class_method :resolve_revocation_metadata
|
|
64
|
+
|
|
65
|
+
def self.require_revocation_https(url, field)
|
|
66
|
+
uri = URI.parse(url) if url.is_a?(String)
|
|
67
|
+
return url if uri.is_a?(URI::HTTPS) && !uri.host.to_s.empty?
|
|
68
|
+
|
|
69
|
+
raise ConfigurationError, "#{field} must be an HTTPS URL"
|
|
70
|
+
rescue URI::InvalidURIError
|
|
71
|
+
raise ConfigurationError, "#{field} must be an HTTPS URL"
|
|
72
|
+
end
|
|
73
|
+
private_class_method :require_revocation_https
|
|
74
|
+
end
|
|
75
|
+
end
|
|
@@ -77,12 +77,11 @@ module Keycardai
|
|
|
77
77
|
end
|
|
78
78
|
|
|
79
79
|
# Client authentication for one request: a newly signed client assertion
|
|
80
|
-
# and its type, as form fields. The assertion's aud is the endpoint
|
|
81
|
-
#
|
|
82
|
-
# invalid_client. Each call signs a new assertion with a new jti.
|
|
80
|
+
# and its type, as form fields. The assertion's aud is the endpoint
|
|
81
|
+
# input. Each call signs a new assertion with a new jti.
|
|
83
82
|
#
|
|
84
83
|
# @param issuer [String, nil] unused; part of the Credential interface
|
|
85
|
-
# @param endpoint [String] the
|
|
84
|
+
# @param endpoint [String] the assertion audience URL
|
|
86
85
|
# @return [ClientAuthentication]
|
|
87
86
|
# @raise [ConfigurationError] when endpoint is missing
|
|
88
87
|
def client_authentication(issuer:, endpoint:)
|
data/lib/keycardai/oauth.rb
CHANGED
|
@@ -12,6 +12,7 @@ require_relative "oauth/client_authentication"
|
|
|
12
12
|
require_relative "oauth/substitute_user"
|
|
13
13
|
require_relative "oauth/pkce"
|
|
14
14
|
require_relative "oauth/authorization_code"
|
|
15
|
+
require_relative "oauth/token_revocation"
|
|
15
16
|
require_relative "oauth/authenticate"
|
|
16
17
|
require_relative "oauth/registration"
|
|
17
18
|
require_relative "oauth/client_secret"
|
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.
|
|
4
|
+
version: 0.12.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Keycard
|
|
@@ -58,6 +58,7 @@ files:
|
|
|
58
58
|
- lib/keycardai/oauth/substitute_user.rb
|
|
59
59
|
- lib/keycardai/oauth/token_exchange_client.rb
|
|
60
60
|
- lib/keycardai/oauth/token_requests.rb
|
|
61
|
+
- lib/keycardai/oauth/token_revocation.rb
|
|
61
62
|
- lib/keycardai/oauth/token_sources.rb
|
|
62
63
|
- lib/keycardai/oauth/token_types.rb
|
|
63
64
|
- lib/keycardai/oauth/token_verifier.rb
|