keycardai-oauth 0.11.4 → 0.13.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 +32 -0
- data/README.md +47 -1
- data/lib/keycardai/oauth/client_authentication.rb +1 -1
- data/lib/keycardai/oauth/credential_discovery.rb +87 -0
- data/lib/keycardai/oauth/discovery.rb +3 -1
- data/lib/keycardai/oauth/errors.rb +30 -3
- data/lib/keycardai/oauth/token_revocation.rb +75 -0
- data/lib/keycardai/oauth/token_sources.rb +4 -5
- data/lib/keycardai/oauth/version.rb +1 -1
- data/lib/keycardai/oauth/web_identity.rb +16 -12
- data/lib/keycardai/oauth.rb +2 -0
- metadata +3 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b621681ef4ce18e982ba67929dd03d87d77d4d192b5f033f41c757216fe5a5f2
|
|
4
|
+
data.tar.gz: b72fee9e5428766e744fba55c4e3d6472d78295d4cf821813bce7c2c6cd8582f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 6b4f0d9bfcaac6d44f753aba01d1fcba3ace14d292821e7ed00c0f0fa3678f90ce06af66ca49764c0dd5fc5dbc484c48b1abd3f1fff9453d5b25e7ec12cd3207
|
|
7
|
+
data.tar.gz: '09f952deebbc83e695d33216a3a8c81b47b6860d85266df3ec166655d5cd71a2e154185021a884cf185134dce7a24776d50a6542ecf82e194fa793780553c640'
|
data/CHANGELOG.md
CHANGED
|
@@ -15,6 +15,38 @@ 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.13.0-keycardai-oauth (2026-11-26)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
- feat(keycardai-oauth): discover the application credential from the environment (SDK-6) (#99)
|
|
22
|
+
- * feat(keycardai-oauth): discover the application credential from the environment (SDK-6)
|
|
23
|
+
- Implements keycardai/keycard-sdk-spec credential-discovery.md v2
|
|
24
|
+
- Refs SDK-6
|
|
25
|
+
- Co-Authored-By: Larry Osakwe <larry@keycard.ai>
|
|
26
|
+
- * docs: count token revocation in the conformance summary
|
|
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.12.0-keycardai-oauth (2026-11-25)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
- feat(keycardai-oauth): token revocation (ID-881) (#97)
|
|
36
|
+
- * feat(keycardai-oauth): token revocation (ID-881)
|
|
37
|
+
- Co-Authored-By: Larry Osakwe <larry@keycard.ai>
|
|
38
|
+
- * docs: record token revocation conformance
|
|
39
|
+
- Co-Authored-By: Larry Osakwe <larry@keycard.ai>
|
|
40
|
+
- * fix(keycardai-oauth): require HTTPS revocation discovery
|
|
41
|
+
- Co-Authored-By: Larry Osakwe <larry@keycard.ai>
|
|
42
|
+
- * fix(keycardai-oauth): use the discovered revocation issuer
|
|
43
|
+
- Co-Authored-By: Larry Osakwe <larry@keycard.ai>
|
|
44
|
+
- * fix(keycardai-oauth): use supplied metadata for revocation audience
|
|
45
|
+
- Co-Authored-By: Larry Osakwe <larry@keycard.ai>
|
|
46
|
+
- ---------
|
|
47
|
+
- Co-authored-by: devin-ai-keycard <devin-ai@keycard.ai>
|
|
48
|
+
Co-authored-by: Larry Osakwe <larry@keycard.ai>
|
|
49
|
+
|
|
18
50
|
## 0.11.4-keycardai-oauth (2026-11-25)
|
|
19
51
|
|
|
20
52
|
|
data/README.md
CHANGED
|
@@ -17,16 +17,43 @@ 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)
|
|
23
24
|
- JWT signing and verification, JWKS keyring with caching
|
|
24
25
|
- Application credentials: ClientSecret (incl. multi-zone), WebIdentity (RFC 7523),
|
|
25
|
-
WorkloadIdentity with pluggable identity token sources
|
|
26
|
+
WorkloadIdentity with pluggable identity token sources, and opt-in discovery
|
|
26
27
|
- AccessContext: the non-throwing per-request container for delegated tokens
|
|
27
28
|
|
|
28
29
|
## Quickstart
|
|
29
30
|
|
|
31
|
+
### Discover an application credential
|
|
32
|
+
|
|
33
|
+
```ruby
|
|
34
|
+
require "keycardai/oauth"
|
|
35
|
+
|
|
36
|
+
credential = Keycardai::OAuth.discover_application_credential
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Discovery runs only when called. It reads the process environment by default,
|
|
40
|
+
or an explicit string-keyed mapping passed as `env:`. It discovers a client
|
|
41
|
+
secret from `KEYCARD_CLIENT_ID` and `KEYCARD_CLIENT_SECRET`, workload identity
|
|
42
|
+
from the first non-empty variable in the `FileTokenSource` discovery list, or
|
|
43
|
+
web identity from `KEYCARD_WEB_IDENTITY_KEY_STORAGE_DIR`.
|
|
44
|
+
|
|
45
|
+
Set `KEYCARD_APPLICATION_CREDENTIAL_TYPE` to `client_secret`,
|
|
46
|
+
`workload_identity`, or `web_identity` to choose one when multiple types are
|
|
47
|
+
configured. `eks_workload_identity` is a deprecated alias for
|
|
48
|
+
`workload_identity`. Selecting `web_identity` without a storage directory uses
|
|
49
|
+
the WebIdentity default, and `web_identity_server_name:` supplies its key name.
|
|
50
|
+
A discovered WebIdentity has no registered client id; construct it explicitly
|
|
51
|
+
with `client_id:` for operations that sign client assertions.
|
|
52
|
+
|
|
53
|
+
Discovery configuration errors raise `Keycardai::OAuth::CredentialDiscoveryError`
|
|
54
|
+
with a symbolic `reason` and a `resolvable` list. Pass the zone URL separately;
|
|
55
|
+
credential discovery does not read `KEYCARD_ZONE_URL`.
|
|
56
|
+
|
|
30
57
|
### Verify an inbound token
|
|
31
58
|
|
|
32
59
|
```ruby
|
|
@@ -132,6 +159,25 @@ credential) for refresh, the code exchange, `authenticate` and device
|
|
|
132
159
|
authorization; without it these raise `ConfigurationError` before any request.
|
|
133
160
|
A credential of your own must respond to `client_authentication`.
|
|
134
161
|
|
|
162
|
+
### Revoke a token
|
|
163
|
+
|
|
164
|
+
Revoking a Keycard refresh token revokes its session. Use the same client
|
|
165
|
+
authentication as for refresh: a public client ID, client ID and secret, or
|
|
166
|
+
`credential:`.
|
|
167
|
+
|
|
168
|
+
```ruby
|
|
169
|
+
Keycardai::OAuth.revoke_token(
|
|
170
|
+
"https://your-zone.keycard.cloud",
|
|
171
|
+
token: stored_refresh_token,
|
|
172
|
+
client_id: ENV.fetch("KEYCARD_CLIENT_ID"),
|
|
173
|
+
client_secret: ENV["KEYCARD_CLIENT_SECRET"], # omit for a public client
|
|
174
|
+
)
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Pass `metadata:` to reuse discovery results. The server must advertise a
|
|
178
|
+
`revocation_endpoint`. The operation returns `nil` on HTTP 200, even for
|
|
179
|
+
unknown, expired, or already revoked tokens. It does not retry.
|
|
180
|
+
|
|
135
181
|
### Sign in a device with no browser
|
|
136
182
|
|
|
137
183
|
The device authorization grant (RFC 8628) gets a token for a person on a
|
|
@@ -43,7 +43,7 @@ module Keycardai
|
|
|
43
43
|
# client_authentication, or when neither credential nor a non-empty
|
|
44
44
|
# client_id is set. A credential that responds to
|
|
45
45
|
# check_client_authentication is checked with it, so a WorkloadIdentity
|
|
46
|
-
# without client_id raises here. Call it before any request.
|
|
46
|
+
# or WebIdentity without client_id raises here. Call it before any request.
|
|
47
47
|
#
|
|
48
48
|
# @raise [ConfigurationError]
|
|
49
49
|
def validate(credential:, client_id:, client_secret: nil)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Keycardai
|
|
4
|
+
# OAuth primitives and application credentials for Keycard.
|
|
5
|
+
module OAuth
|
|
6
|
+
# Builds the application credential described by the environment.
|
|
7
|
+
#
|
|
8
|
+
# @param env [#[]] mapping with environment variable names as string keys
|
|
9
|
+
# @param web_identity_server_name [String, nil] name used for the WebIdentity key id
|
|
10
|
+
# @return [ClientSecret, WorkloadIdentity, WebIdentity]
|
|
11
|
+
# @raise [CredentialDiscoveryError] the configuration does not select a usable credential
|
|
12
|
+
# @raise [WorkloadIdentityConfigurationError] the selected token file is missing or empty
|
|
13
|
+
def self.discover_application_credential(env: ENV, web_identity_server_name: nil)
|
|
14
|
+
CredentialDiscovery.new(env).discover(web_identity_server_name)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Resolves and constructs a credential from one environment mapping.
|
|
18
|
+
class CredentialDiscovery
|
|
19
|
+
SELECTOR = "KEYCARD_APPLICATION_CREDENTIAL_TYPE"
|
|
20
|
+
STORAGE_DIR = "KEYCARD_WEB_IDENTITY_KEY_STORAGE_DIR"
|
|
21
|
+
TYPES = %w[client_secret workload_identity web_identity].freeze
|
|
22
|
+
|
|
23
|
+
def initialize(env)
|
|
24
|
+
@client_id = value(env, "KEYCARD_CLIENT_ID")
|
|
25
|
+
@client_secret = value(env, "KEYCARD_CLIENT_SECRET")
|
|
26
|
+
@token_file = FileTokenSource::DEFAULT_ENV_VARS.lazy.filter_map { |name| value(env, name) }.first
|
|
27
|
+
@storage_dir = value(env, STORAGE_DIR)
|
|
28
|
+
@selector = value(env, SELECTOR)
|
|
29
|
+
@resolvable = []
|
|
30
|
+
@resolvable << "client_secret" if @client_id && @client_secret
|
|
31
|
+
@resolvable << "workload_identity" if @token_file
|
|
32
|
+
@resolvable << "web_identity" if @storage_dir
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def discover(web_identity_server_name)
|
|
36
|
+
case @selector ? selected_type : inferred_type
|
|
37
|
+
when "client_secret"
|
|
38
|
+
ClientSecret.new(@client_id, @client_secret)
|
|
39
|
+
when "workload_identity"
|
|
40
|
+
WorkloadIdentity.new(source: FileTokenSource.new(token_file_path: @token_file), client_id: @client_id)
|
|
41
|
+
when "web_identity"
|
|
42
|
+
WebIdentity.new(server_name: web_identity_server_name, storage_dir: @storage_dir)
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def value(env, name)
|
|
49
|
+
value = env[name]
|
|
50
|
+
value if value && !value.empty?
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def selected_type
|
|
54
|
+
type = @selector == "eks_workload_identity" ? "workload_identity" : @selector
|
|
55
|
+
fail_discovery(:unknown_type, "Unknown #{SELECTOR}; use one of #{TYPES.join(", ")}") unless TYPES.include?(type)
|
|
56
|
+
return type if type == "web_identity" || @resolvable.include?(type)
|
|
57
|
+
|
|
58
|
+
inputs = if type == "client_secret"
|
|
59
|
+
"both KEYCARD_CLIENT_ID and KEYCARD_CLIENT_SECRET"
|
|
60
|
+
else
|
|
61
|
+
"a token file path in one of #{FileTokenSource::DEFAULT_ENV_VARS.join(", ")}"
|
|
62
|
+
end
|
|
63
|
+
fail_discovery(:not_satisfiable, "#{SELECTOR}=#{type} requires #{inputs}")
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def inferred_type
|
|
67
|
+
if @client_secret && !@client_id
|
|
68
|
+
fail_discovery(:incomplete, "KEYCARD_CLIENT_SECRET is set without KEYCARD_CLIENT_ID")
|
|
69
|
+
end
|
|
70
|
+
if @resolvable.empty?
|
|
71
|
+
fail_discovery(:absent, "No application credential found in the environment. Set KEYCARD_CLIENT_ID " \
|
|
72
|
+
"and KEYCARD_CLIENT_SECRET, a token file variable, or #{STORAGE_DIR}")
|
|
73
|
+
end
|
|
74
|
+
if @resolvable.size > 1
|
|
75
|
+
fail_discovery(:ambiguous, "The environment configures #{@resolvable.join(" and ")}. " \
|
|
76
|
+
"Set #{SELECTOR} to choose one")
|
|
77
|
+
end
|
|
78
|
+
@resolvable.first
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def fail_discovery(reason, message)
|
|
82
|
+
raise CredentialDiscoveryError.new(message, reason: reason, resolvable: @resolvable)
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
private_constant :CredentialDiscovery
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -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,33 @@ 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
|
|
16
|
+
|
|
17
|
+
# The environment does not describe a single usable application credential.
|
|
18
|
+
class CredentialDiscoveryError < ConfigurationError
|
|
19
|
+
# @return [Symbol] absent, ambiguous, incomplete, unknown_type, or not_satisfiable
|
|
20
|
+
attr_reader :reason
|
|
21
|
+
# @return [Array<String>] canonical credential types the environment configures
|
|
22
|
+
attr_reader :resolvable
|
|
23
|
+
|
|
24
|
+
def initialize(message, reason:, resolvable:)
|
|
25
|
+
super(message)
|
|
26
|
+
@reason = reason
|
|
27
|
+
@resolvable = resolvable.dup.freeze
|
|
28
|
+
end
|
|
29
|
+
end
|
|
12
30
|
|
|
13
31
|
# A transport-level failure (DNS, TLS, timeout) wrapping the underlying
|
|
14
32
|
# exception as +cause+.
|
|
15
|
-
class NetworkError < Keycardai::Error
|
|
33
|
+
class NetworkError < Keycardai::Error
|
|
34
|
+
def retryable?
|
|
35
|
+
true
|
|
36
|
+
end
|
|
37
|
+
end
|
|
16
38
|
|
|
17
39
|
# A non-2xx HTTP response. Has the status code and response body.
|
|
18
40
|
class HTTPError < Keycardai::Error
|
|
@@ -28,6 +50,11 @@ module Keycardai
|
|
|
28
50
|
@body = body
|
|
29
51
|
@retry_after = retry_after
|
|
30
52
|
end
|
|
53
|
+
|
|
54
|
+
# @return [Boolean] whether repeating the request unchanged could succeed
|
|
55
|
+
def retryable?
|
|
56
|
+
status == 429 || (500..599).cover?(status)
|
|
57
|
+
end
|
|
31
58
|
end
|
|
32
59
|
|
|
33
60
|
# An OAuth error response from the authorization server (RFC 6749 §5.2).
|
|
@@ -54,7 +81,7 @@ module Keycardai
|
|
|
54
81
|
|
|
55
82
|
# @return [Boolean] whether repeating the request unchanged could succeed
|
|
56
83
|
def retryable?
|
|
57
|
-
|
|
84
|
+
super || !PERMANENT_ERROR_CODES.include?(error)
|
|
58
85
|
end
|
|
59
86
|
end
|
|
60
87
|
|
|
@@ -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
|
|
@@ -10,11 +10,10 @@ module Keycardai
|
|
|
10
10
|
# Covers EKS (AWS_* env vars), AKS (AZURE_FEDERATED_TOKEN_FILE), any
|
|
11
11
|
# Kubernetes projected service-account token, and file-mode CI providers.
|
|
12
12
|
#
|
|
13
|
-
# Path discovery through the well-known env vars
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
#
|
|
17
|
-
# non-empty), preserving fail-fast behavior.
|
|
13
|
+
# Path discovery through the well-known env vars follows a platform
|
|
14
|
+
# convention. An explicit token_file_path wins; env_var_name is consulted
|
|
15
|
+
# first when given. The resolved file must exist and be non-empty at
|
|
16
|
+
# construction.
|
|
18
17
|
class FileTokenSource
|
|
19
18
|
DEFAULT_ENV_VARS = %w[
|
|
20
19
|
KEYCARD_EKS_WORKLOAD_IDENTITY_TOKEN_FILE
|
|
@@ -14,8 +14,8 @@ module Keycardai
|
|
|
14
14
|
# Holds no shared secret and contributes no Basic header. Never reads
|
|
15
15
|
# environment variables; the caller supplies storage configuration.
|
|
16
16
|
class WebIdentity
|
|
17
|
-
# @param client_id [String] the registered OAuth client id, signed
|
|
18
|
-
# the assertion's iss and sub
|
|
17
|
+
# @param client_id [String, nil] the registered OAuth client id, signed
|
|
18
|
+
# as the assertion's iss and sub; required for client authentication
|
|
19
19
|
# @param server_name [String, nil] sanitized into the key id when no
|
|
20
20
|
# key_id is given
|
|
21
21
|
# @param key_id [String, nil] explicit key id (the JWT kid); otherwise
|
|
@@ -23,11 +23,8 @@ module Keycardai
|
|
|
23
23
|
# @param storage [#load, #store, nil] pluggable keypair storage
|
|
24
24
|
# @param storage_dir [String, nil] directory for the default file store
|
|
25
25
|
# @param clock [#call] returns the current Time; override in tests
|
|
26
|
-
|
|
27
|
-
def initialize(client_id:, server_name: nil, key_id: nil, storage: nil, storage_dir: nil,
|
|
26
|
+
def initialize(client_id: nil, server_name: nil, key_id: nil, storage: nil, storage_dir: nil,
|
|
28
27
|
clock: -> { Time.now })
|
|
29
|
-
raise ConfigurationError, "WebIdentity requires a client_id" if client_id.nil? || client_id.empty?
|
|
30
|
-
|
|
31
28
|
@client_id = client_id
|
|
32
29
|
storage ||= FilePrivateKeyStorage.new(dir: storage_dir || FilePrivateKeyStorage::DEFAULT_DIR)
|
|
33
30
|
@key_manager = PrivateKeyManager.new(
|
|
@@ -59,7 +56,7 @@ module Keycardai
|
|
|
59
56
|
# @param scope [String, nil]
|
|
60
57
|
# @param issuer [String, nil] unused; part of the Credential interface
|
|
61
58
|
# @return [Hash]
|
|
62
|
-
# @raise [ConfigurationError] when token_endpoint is missing
|
|
59
|
+
# @raise [ConfigurationError] when the client_id or token_endpoint is missing
|
|
63
60
|
def prepare_token_exchange_request(subject_token:, token_endpoint: nil, resource: nil,
|
|
64
61
|
audience: nil, scope: nil, issuer: nil)
|
|
65
62
|
if token_endpoint.nil? || token_endpoint.empty?
|
|
@@ -77,24 +74,31 @@ module Keycardai
|
|
|
77
74
|
end
|
|
78
75
|
|
|
79
76
|
# 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.
|
|
77
|
+
# and its type, as form fields. The assertion's aud is the endpoint
|
|
78
|
+
# input. Each call signs a new assertion with a new jti.
|
|
83
79
|
#
|
|
84
80
|
# @param issuer [String, nil] unused; part of the Credential interface
|
|
85
|
-
# @param endpoint [String] the
|
|
81
|
+
# @param endpoint [String] the assertion audience URL
|
|
86
82
|
# @return [ClientAuthentication]
|
|
87
|
-
# @raise [ConfigurationError] when endpoint is missing
|
|
83
|
+
# @raise [ConfigurationError] when the client_id or endpoint is missing
|
|
88
84
|
def client_authentication(issuer:, endpoint:)
|
|
89
85
|
if endpoint.nil? || endpoint.empty?
|
|
90
86
|
raise ConfigurationError, "WebIdentity requires the endpoint URL as the assertion audience"
|
|
91
87
|
end
|
|
92
88
|
|
|
89
|
+
check_client_authentication
|
|
93
90
|
assertion = @key_manager.create_client_assertion(client_id: @client_id, audience: endpoint)
|
|
94
91
|
ClientAuthentication.new(params: { "client_assertion" => assertion,
|
|
95
92
|
"client_assertion_type" => PrivateKeyManager::ASSERTION_TYPE })
|
|
96
93
|
end
|
|
97
94
|
|
|
95
|
+
# @raise [ConfigurationError] when the client_id is missing
|
|
96
|
+
def check_client_authentication
|
|
97
|
+
return unless @client_id.nil? || @client_id.empty?
|
|
98
|
+
|
|
99
|
+
raise ConfigurationError, "WebIdentity requires a client_id for client authentication"
|
|
100
|
+
end
|
|
101
|
+
|
|
98
102
|
# The public JWKS the authorization server verifies assertions against.
|
|
99
103
|
#
|
|
100
104
|
# @return [Hash] {"keys" => [...]}
|
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"
|
|
@@ -19,6 +20,7 @@ require_relative "oauth/private_key"
|
|
|
19
20
|
require_relative "oauth/web_identity"
|
|
20
21
|
require_relative "oauth/workload_identity"
|
|
21
22
|
require_relative "oauth/token_sources"
|
|
23
|
+
require_relative "oauth/credential_discovery"
|
|
22
24
|
require_relative "oauth/access_context"
|
|
23
25
|
require_relative "oauth/exchange_tokens"
|
|
24
26
|
require_relative "oauth/token_verifier"
|
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.13.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Keycard
|
|
@@ -43,6 +43,7 @@ files:
|
|
|
43
43
|
- lib/keycardai/oauth/client_authentication.rb
|
|
44
44
|
- lib/keycardai/oauth/client_credentials_client.rb
|
|
45
45
|
- lib/keycardai/oauth/client_secret.rb
|
|
46
|
+
- lib/keycardai/oauth/credential_discovery.rb
|
|
46
47
|
- lib/keycardai/oauth/device_authorization.rb
|
|
47
48
|
- lib/keycardai/oauth/discovery.rb
|
|
48
49
|
- lib/keycardai/oauth/errors.rb
|
|
@@ -58,6 +59,7 @@ files:
|
|
|
58
59
|
- lib/keycardai/oauth/substitute_user.rb
|
|
59
60
|
- lib/keycardai/oauth/token_exchange_client.rb
|
|
60
61
|
- lib/keycardai/oauth/token_requests.rb
|
|
62
|
+
- lib/keycardai/oauth/token_revocation.rb
|
|
61
63
|
- lib/keycardai/oauth/token_sources.rb
|
|
62
64
|
- lib/keycardai/oauth/token_types.rb
|
|
63
65
|
- lib/keycardai/oauth/token_verifier.rb
|