token_authority 0.2.1 → 0.3.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 +42 -1
- data/README.md +52 -14
- data/app/controllers/concerns/token_authority/initial_access_token_authentication.rb +2 -2
- data/app/controllers/token_authority/protected_resource_metadata_controller.rb +39 -0
- data/app/helpers/token_authority/authorization_grants_helper.rb +2 -3
- data/app/models/concerns/token_authority/claim_validatable.rb +2 -2
- data/app/models/concerns/token_authority/resourceable.rb +2 -2
- data/app/models/token_authority/access_token.rb +2 -2
- data/app/models/token_authority/access_token_request.rb +1 -1
- data/app/models/token_authority/authorization_request.rb +2 -2
- data/app/models/token_authority/authorization_server_metadata.rb +4 -4
- data/app/models/token_authority/client.rb +4 -4
- data/app/models/token_authority/client_metadata_document.rb +2 -2
- data/app/models/token_authority/client_registration_request.rb +5 -5
- data/app/models/token_authority/jwks_fetcher.rb +1 -1
- data/app/models/token_authority/protected_resource_metadata.rb +110 -31
- data/app/models/token_authority/refresh_token.rb +2 -2
- data/app/models/token_authority/refresh_token_request.rb +1 -1
- data/lib/generators/token_authority/install/templates/token_authority.rb +100 -114
- data/lib/token_authority/configuration.rb +345 -175
- data/lib/token_authority/errors.rb +29 -0
- data/lib/token_authority/routing/constraints.rb +2 -2
- data/lib/token_authority/routing/routes.rb +74 -16
- data/lib/token_authority/version.rb +1 -1
- data/lib/token_authority.rb +2 -2
- metadata +2 -2
- data/app/controllers/token_authority/resource_metadata_controller.rb +0 -12
|
@@ -58,7 +58,7 @@ module TokenAuthority
|
|
|
58
58
|
return if resources.empty?
|
|
59
59
|
|
|
60
60
|
# If resources are provided but feature is disabled, reject them
|
|
61
|
-
unless TokenAuthority.config.
|
|
61
|
+
unless TokenAuthority.config.resources_enabled?
|
|
62
62
|
errors.add(:resources, :not_allowed)
|
|
63
63
|
return
|
|
64
64
|
end
|
|
@@ -10,25 +10,19 @@ TokenAuthority.configure do |config|
|
|
|
10
10
|
# secret_key_base from credentials or configuration.
|
|
11
11
|
config.secret_key = Rails.application.credentials.secret_key_base || Rails.application.secret_key_base
|
|
12
12
|
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
#
|
|
18
|
-
# Used as the "aud" (audience) claim in issued tokens.
|
|
19
|
-
config.rfc_9068_audience_url = ENV.fetch("TOKEN_AUTHORITY_AUDIENCE_URL", "http://localhost:3000/api/")
|
|
20
|
-
|
|
21
|
-
# The issuer URL for JWT tokens. This is typically your application's base URL.
|
|
22
|
-
# Used as the "iss" (issuer) claim in issued tokens.
|
|
23
|
-
config.rfc_9068_issuer_url = ENV.fetch("TOKEN_AUTHORITY_ISSUER_URL", "http://localhost:3000/")
|
|
13
|
+
# Enable event logging (default: true).
|
|
14
|
+
# When enabled, events are emitted and logged to Rails.logger.
|
|
15
|
+
# Events include: authorization requests, consent actions, token exchanges,
|
|
16
|
+
# token refreshes, revocations, client authentication, and security events.
|
|
17
|
+
# config.event_logging_enabled = true
|
|
24
18
|
|
|
25
|
-
#
|
|
26
|
-
#
|
|
27
|
-
#
|
|
19
|
+
# Enable debug events (default: false).
|
|
20
|
+
# Debug events provide detailed information useful during development,
|
|
21
|
+
# such as PKCE validation steps and cache hits/misses.
|
|
22
|
+
# config.event_logging_debug_events = false
|
|
28
23
|
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
# config.rfc_9068_default_refresh_token_duration = 1_209_600
|
|
24
|
+
# Enable ActiveSupport::Notifications instrumentation (default: true).
|
|
25
|
+
# config.instrumentation_enabled = true
|
|
32
26
|
|
|
33
27
|
# ==========================================================================
|
|
34
28
|
# User Authentication
|
|
@@ -62,131 +56,143 @@ TokenAuthority.configure do |config|
|
|
|
62
56
|
config.error_page_layout = "application"
|
|
63
57
|
|
|
64
58
|
# ==========================================================================
|
|
65
|
-
#
|
|
59
|
+
# Scopes
|
|
66
60
|
# ==========================================================================
|
|
67
61
|
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
#
|
|
62
|
+
# Configure allowed scopes with human-friendly display names.
|
|
63
|
+
# Keys are the scope strings (used as the allowlist), values are display names
|
|
64
|
+
# shown on the consent screen.
|
|
65
|
+
#
|
|
66
|
+
# IMPORTANT: You must configure at least one scope since require_scope is true by default.
|
|
67
|
+
config.scopes = {
|
|
68
|
+
"read" => "Read access to your data",
|
|
69
|
+
"write" => "Write access to your data"
|
|
70
|
+
}
|
|
71
71
|
|
|
72
|
-
#
|
|
73
|
-
#
|
|
72
|
+
# Require the scope parameter in authorization requests (default: true).
|
|
73
|
+
# When true, clients must specify at least one scope.
|
|
74
|
+
# config.require_scope = true
|
|
74
75
|
|
|
75
76
|
# ==========================================================================
|
|
76
|
-
#
|
|
77
|
+
# Resources (RFC 9728 / RFC 8707)
|
|
77
78
|
# ==========================================================================
|
|
78
79
|
|
|
79
|
-
#
|
|
80
|
-
#
|
|
81
|
-
#
|
|
82
|
-
|
|
83
|
-
#
|
|
84
|
-
#
|
|
85
|
-
#
|
|
86
|
-
|
|
87
|
-
#
|
|
88
|
-
#
|
|
89
|
-
#
|
|
90
|
-
|
|
91
|
-
#
|
|
92
|
-
#
|
|
93
|
-
|
|
94
|
-
#
|
|
95
|
-
#
|
|
96
|
-
|
|
97
|
-
#
|
|
98
|
-
#
|
|
99
|
-
|
|
100
|
-
#
|
|
101
|
-
#
|
|
102
|
-
|
|
103
|
-
# URL
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
80
|
+
# Protected resources keyed by identifier. For single-resource deployments,
|
|
81
|
+
# just configure one entry - it will be used for all requests.
|
|
82
|
+
# For multi-resource deployments, add entries for each subdomain.
|
|
83
|
+
# The first entry is used as the default when no subdomain matches.
|
|
84
|
+
#
|
|
85
|
+
# Each entry must include the :resource field (required per RFC 9728).
|
|
86
|
+
# The :resource URL is used as the audience (aud) claim in access tokens.
|
|
87
|
+
# The first :authorization_servers entry is used as the issuer (iss) claim.
|
|
88
|
+
#
|
|
89
|
+
# Resource indicators (RFC 8707) are automatically enabled when resources are
|
|
90
|
+
# configured. The allowlist of valid resource URIs is derived from the :resource
|
|
91
|
+
# key in the configuration below.
|
|
92
|
+
#
|
|
93
|
+
# IMPORTANT: You must configure at least one resource since require_resource is true by default.
|
|
94
|
+
#
|
|
95
|
+
# Available options:
|
|
96
|
+
# resource (required) - The protected resource URI (used as aud claim)
|
|
97
|
+
# resource_name - Human-readable name shown on consent screen
|
|
98
|
+
# scopes_supported - Array of scopes this resource accepts
|
|
99
|
+
# authorization_servers - Array of auth server URLs (first used as iss claim)
|
|
100
|
+
# bearer_methods_supported - Array of supported bearer token methods
|
|
101
|
+
# jwks_uri - URI for JSON Web Key Set endpoint
|
|
102
|
+
# resource_documentation - URL for API documentation
|
|
103
|
+
# resource_policy_uri - URL for privacy policy
|
|
104
|
+
# resource_tos_uri - URL for terms of service
|
|
105
|
+
config.resources = {
|
|
106
|
+
api: {
|
|
107
|
+
resource: ENV.fetch("TOKEN_AUTHORITY_RESOURCE_URL", "http://localhost:3000/api"),
|
|
108
|
+
resource_name: "My API",
|
|
109
|
+
scopes_supported: %w[read write],
|
|
110
|
+
authorization_servers: [ENV.fetch("TOKEN_AUTHORITY_BASE_URL", "http://localhost:3000")],
|
|
111
|
+
bearer_methods_supported: ["header"],
|
|
112
|
+
resource_documentation: "http://localhost:3000/docs/api"
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
# Require the resource parameter in authorization requests (default: true).
|
|
117
|
+
# When true, clients must specify at least one resource.
|
|
118
|
+
# config.require_resource = true
|
|
108
119
|
|
|
109
120
|
# ==========================================================================
|
|
110
|
-
#
|
|
121
|
+
# JWT Access Tokens (RFC 9068)
|
|
111
122
|
# ==========================================================================
|
|
112
123
|
|
|
113
|
-
#
|
|
114
|
-
#
|
|
115
|
-
#
|
|
116
|
-
#
|
|
117
|
-
#
|
|
118
|
-
# When configured, only these scopes are allowed in authorization requests.
|
|
119
|
-
# config.scopes = {
|
|
120
|
-
# "read" => "Read access to your data",
|
|
121
|
-
# "write" => "Write access to your data"
|
|
122
|
-
# }
|
|
124
|
+
# The issuer URL for JWT tokens (default: nil).
|
|
125
|
+
# Used as the "iss" (issuer) claim in issued tokens.
|
|
126
|
+
# If nil, the issuer is derived from the first resource's :authorization_servers.
|
|
127
|
+
# You must configure either this OR :authorization_servers on at least one resource.
|
|
128
|
+
# config.token_issuer_url = nil
|
|
123
129
|
|
|
124
|
-
#
|
|
125
|
-
# When
|
|
126
|
-
# config.
|
|
130
|
+
# The audience URL for JWT tokens (default: nil).
|
|
131
|
+
# When set, this value is used as the "aud" claim for all tokens.
|
|
132
|
+
# When nil (recommended), the audience is the resource URL from config.resources.
|
|
133
|
+
# config.token_audience_url = nil
|
|
134
|
+
|
|
135
|
+
# Default duration for access tokens in seconds (5 minutes).
|
|
136
|
+
# This value is used when creating new clients without explicit durations.
|
|
137
|
+
# config.default_access_token_duration = 300
|
|
138
|
+
|
|
139
|
+
# Default duration for refresh tokens in seconds (14 days).
|
|
140
|
+
# This value is used when creating new clients without explicit durations.
|
|
141
|
+
# config.default_refresh_token_duration = 1_209_600
|
|
127
142
|
|
|
128
143
|
# ==========================================================================
|
|
129
|
-
#
|
|
144
|
+
# Server Metadata (RFC 8414)
|
|
130
145
|
# ==========================================================================
|
|
131
146
|
|
|
132
|
-
#
|
|
133
|
-
#
|
|
134
|
-
#
|
|
135
|
-
#
|
|
136
|
-
# Set to nil or {} to disable resource indicators entirely.
|
|
137
|
-
# When configured, only these resources are allowed in authorization requests.
|
|
138
|
-
# config.rfc_8707_resources = {
|
|
139
|
-
# "https://api.example.com/" => "Main API",
|
|
140
|
-
# "https://billing.example.com/" => "Billing Service"
|
|
141
|
-
# }
|
|
147
|
+
# URL to developer documentation for your OAuth server.
|
|
148
|
+
# Included in the /.well-known/oauth-authorization-server response.
|
|
149
|
+
# config.authorization_server_documentation = "https://example.com/docs/oauth"
|
|
142
150
|
|
|
143
|
-
#
|
|
144
|
-
#
|
|
145
|
-
# config.rfc_8707_require_resource = false
|
|
151
|
+
# Note: scopes_supported in the metadata response is automatically derived
|
|
152
|
+
# from the keys of config.scopes (see Scopes section above).
|
|
146
153
|
|
|
147
154
|
# ==========================================================================
|
|
148
155
|
# Dynamic Client Registration (RFC 7591)
|
|
149
156
|
# ==========================================================================
|
|
150
157
|
|
|
151
|
-
# Enable dynamic client registration endpoint (/register).
|
|
158
|
+
# Enable dynamic client registration endpoint (/register) (default: true).
|
|
152
159
|
# When enabled, clients can register programmatically via POST requests.
|
|
153
|
-
#
|
|
154
|
-
# config.rfc_7591_enabled = false
|
|
160
|
+
# config.dcr_enabled = true
|
|
155
161
|
|
|
156
|
-
# Require an initial access token for client registration.
|
|
162
|
+
# Require an initial access token for client registration (default: false).
|
|
157
163
|
# When enabled, registration requests must include a Bearer token.
|
|
158
|
-
# config.
|
|
164
|
+
# config.dcr_require_initial_access_token = false
|
|
159
165
|
|
|
160
166
|
# Validator proc for initial access tokens.
|
|
161
167
|
# Must return true if the token is valid, false otherwise.
|
|
162
168
|
# Example:
|
|
163
|
-
# config.
|
|
169
|
+
# config.dcr_initial_access_token_validator = ->(token) {
|
|
164
170
|
# token == ENV["REGISTRATION_ACCESS_TOKEN"]
|
|
165
171
|
# }
|
|
166
172
|
|
|
167
173
|
# Allowed grant types for dynamically registered clients.
|
|
168
|
-
# config.
|
|
174
|
+
# config.dcr_allowed_grant_types = %w[authorization_code refresh_token]
|
|
169
175
|
|
|
170
176
|
# Allowed response types for dynamically registered clients.
|
|
171
|
-
# config.
|
|
177
|
+
# config.dcr_allowed_response_types = %w[code]
|
|
172
178
|
|
|
173
179
|
# Allowed token endpoint authentication methods.
|
|
174
180
|
# Options: none, client_secret_basic, client_secret_post, client_secret_jwt, private_key_jwt
|
|
175
|
-
# config.
|
|
181
|
+
# config.dcr_allowed_token_endpoint_auth_methods = %w[none client_secret_basic client_secret_post client_secret_jwt private_key_jwt]
|
|
176
182
|
|
|
177
183
|
# Client secret expiration duration in seconds (nil = never expires).
|
|
178
|
-
# config.
|
|
184
|
+
# config.dcr_client_secret_expiration = nil
|
|
179
185
|
|
|
180
186
|
# JWKS for verifying software statements (signed JWTs with client metadata).
|
|
181
187
|
# Set to a JWKS hash to enable software statement verification.
|
|
182
|
-
# config.
|
|
188
|
+
# config.dcr_software_statement_jwks = nil
|
|
183
189
|
|
|
184
190
|
# Require software statements for client registration.
|
|
185
191
|
# When enabled, registration requests must include a valid software_statement.
|
|
186
|
-
# config.
|
|
192
|
+
# config.dcr_software_statement_required = false
|
|
187
193
|
|
|
188
194
|
# Cache TTL in seconds for fetched JWKS from jwks_uri (default: 1 hour).
|
|
189
|
-
# config.
|
|
195
|
+
# config.dcr_jwks_cache_ttl = 3600
|
|
190
196
|
|
|
191
197
|
# ==========================================================================
|
|
192
198
|
# Client Metadata Document (draft-ietf-oauth-client-id-metadata-document)
|
|
@@ -224,24 +230,4 @@ TokenAuthority.configure do |config|
|
|
|
224
230
|
# Connection and read timeouts in seconds (default: 5 each).
|
|
225
231
|
# config.client_metadata_document_connect_timeout = 5
|
|
226
232
|
# config.client_metadata_document_read_timeout = 5
|
|
227
|
-
|
|
228
|
-
# ==========================================================================
|
|
229
|
-
# Event Logging
|
|
230
|
-
# ==========================================================================
|
|
231
|
-
|
|
232
|
-
# TokenAuthority emits structured events using Rails 8.1's event reporting.
|
|
233
|
-
# Events are automatically logged to Rails.logger when enabled.
|
|
234
|
-
#
|
|
235
|
-
# Events include: authorization requests, consent actions, token exchanges,
|
|
236
|
-
# token refreshes, revocations, client authentication, and security events
|
|
237
|
-
# (e.g., token theft detection).
|
|
238
|
-
|
|
239
|
-
# Enable event logging (default: true).
|
|
240
|
-
# When enabled, events are emitted and logged to Rails.logger.
|
|
241
|
-
# config.event_logging_enabled = true
|
|
242
|
-
|
|
243
|
-
# Enable debug events (default: false).
|
|
244
|
-
# Debug events provide detailed information useful during development,
|
|
245
|
-
# such as PKCE validation steps and cache hits/misses.
|
|
246
|
-
# config.event_logging_debug_events = false
|
|
247
233
|
end
|