jwt_auth_cognito 1.0.0.pre.beta.1 → 1.0.0.pre.beta.3

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: 4b2b634f054c3fc1bfda6e0e63ffca5138547b23b11eff699faf23152491764a
4
- data.tar.gz: df5e63158c0ac35b9530dc09ce74cf207a08897a8480c1aa5bcb1b9c177bd6e3
3
+ metadata.gz: 87913fe629cb36042e7d267bbb0cf3a814a8eb1289971a7192f600be8cf781b3
4
+ data.tar.gz: fe5b1f73de56acc80cc5f646a095093436255ee3b857534d6f5db2b0c34c2274
5
5
  SHA512:
6
- metadata.gz: 034cd66eeb8c72a3446f32a74f1f73b17e78c4c24f566c2bbaacb017568d4e73faee63c9c53c4aecd658b11ee472d8912a9e87da1695a869590210b8c820b2ae
7
- data.tar.gz: f00152cc1067ebda1630768f93ab7fb5053372c13e67b94ef08f6cdc5fde421e008c326c6ea454d0839b71b525dbf1daf16a94aa14fbb759ceb07dd150cd9477
6
+ metadata.gz: 41826e498618bd98a002e66a4f015610249645a15652528b540545114af8d8336c52f6186edc9a85dcd23159798ed6fdbd8f3038073704ef5fa9c61ec03ed0cf
7
+ data.tar.gz: 643d331d2b80d775d7011f86d1a76614425064d36e0513dc50e18a3a96fb1757c71a13303690d017743d70c1c783c60bd532c060f6b4299c64145855cb8eb98b
data/.rubocop.yml CHANGED
@@ -75,4 +75,7 @@ Metrics/CyclomaticComplexity:
75
75
  Enabled: false
76
76
 
77
77
  Metrics/PerceivedComplexity:
78
+ Enabled: false
79
+
80
+ Metrics/ClassLength:
78
81
  Enabled: false
data/CHANGELOG.md CHANGED
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [1.0.0-beta.3] - 2025-01-16
11
+
12
+ ### Fixed
13
+
14
+ - **System API Key Bypass**: Fixed appId validation to correctly bypass for system API keys
15
+ - System API keys now have transversal access to all applications as intended
16
+ - App API keys continue to be restricted to their specific application
17
+ - Uses existing `can_access_app?` method from `ApiKeyValidator` for consistent logic
18
+ - Maintains security while allowing system-level administrative access
19
+
20
+ ## [1.0.0-beta.2] - 2025-01-16
21
+
22
+ ### Improved
23
+
24
+ - **Documentation Enhancement**: Added Redis configuration documentation to main usage patterns
25
+ - Updated README.md with complete Redis connection setup in factory method
26
+ - Enhanced CLAUDE.md with Redis configuration in the main usage pattern
27
+ - Improved clarity on how to connect Redis for token blacklisting and user data enrichment
28
+
10
29
  ## [0.3.0] - 2024-01-15
11
30
 
12
31
  ### Added
data/CLAUDE.md CHANGED
@@ -145,6 +145,56 @@ ENV['REDIS_CA_CERT'] = "-----BEGIN CERTIFICATE-----..."
145
145
  - **Backward Compatibility**: All functionality works without client secret configuration
146
146
  - **Security Integration**: Secret hash automatically included in blacklist operations when configured
147
147
 
148
+ ### System API Key Support
149
+ - **System API Key Bypass**: API keys with scope 'system' can access any application (transversal access)
150
+ - **App API Key Restrictions**: API keys with scope 'app' are restricted to their specific application
151
+ - **Automatic Detection**: Uses existing `can_access_app?` method from `ApiKeyValidator` for consistent logic
152
+ - **Security Maintained**: Preserves security boundaries while enabling administrative functionality
153
+
154
+ ## 🚀 Main Usage Pattern with Redis Connection
155
+
156
+ ### ✨ Complete Setup with Redis Connection
157
+
158
+ ```ruby
159
+ # Create validator with Redis connection for blacklist and user data
160
+ validator = JwtAuthCognito.create_cognito_validator(
161
+ region: 'us-east-1',
162
+ user_pool_id: 'us-east-1_ExamplePool',
163
+ client_id: 'your-client-id',
164
+ client_secret: 'your-client-secret', # Optional
165
+ redis_config: {
166
+ # Redis configuration for token blacklisting and user data enrichment
167
+ host: ENV['REDIS_HOST'] || 'localhost',
168
+ port: ENV['REDIS_PORT']&.to_i || 6379,
169
+ password: ENV['REDIS_PASSWORD'],
170
+ db: ENV['REDIS_DB']&.to_i || 0,
171
+
172
+ # TLS configuration for secure connections
173
+ tls: ENV['REDIS_TLS'] == 'true',
174
+ ca_cert_path: ENV['REDIS_CA_CERT_PATH'],
175
+ ca_cert_name: ENV['REDIS_CA_CERT_NAME'],
176
+ verify_mode: ENV['REDIS_VERIFY_MODE'] || 'peer'
177
+ },
178
+ enable_user_data_retrieval: true
179
+ )
180
+
181
+ # Initialize Redis connection and services
182
+ validator.initialize!
183
+
184
+ # 🌟 Main validation method with complete functionality
185
+ result = validator.validate_token_enriched(token)
186
+
187
+ if result[:valid]
188
+ puts "✅ Valid token:"
189
+ puts "User: #{result[:sub]}"
190
+ puts "Permissions: #{result[:user_permissions]}"
191
+ puts "Organizations: #{result[:user_organizations]}"
192
+ puts "Applications: #{result[:applications]}"
193
+ else
194
+ puts "❌ Invalid token: #{result[:error]}"
195
+ end
196
+ ```
197
+
148
198
  ## Environment Configuration
149
199
 
150
200
  The gem supports extensive environment variable configuration for deployment flexibility:
@@ -152,7 +202,7 @@ The gem supports extensive environment variable configuration for deployment fle
152
202
  ### AWS Cognito Configuration
153
203
  ```bash
154
204
  COGNITO_REGION=us-east-1
155
- COGNITO_USER_POOL_ID=us-east-1_AbCdEfGhI
205
+ COGNITO_USER_POOL_ID=us-east-1_AbCdEfGhI
156
206
  COGNITO_CLIENT_ID=your-client-id
157
207
  COGNITO_CLIENT_SECRET=your-client-secret # Optional for enhanced security
158
208
  ```
data/README.md CHANGED
@@ -162,21 +162,41 @@ end
162
162
  ### Factory Method para Configuración Simplificada (Nuevo v0.3.0)
163
163
 
164
164
  ```ruby
165
- # Crear validador con una línea
165
+ # Crear validador con conexión Redis completa
166
166
  validator = JwtAuthCognito.create_cognito_validator(
167
167
  region: 'us-east-1',
168
168
  user_pool_id: 'us-east-1_ExamplePool',
169
169
  client_id: 'your-client-id',
170
170
  redis_config: {
171
- host: 'localhost',
172
- port: 6379,
173
- tls: true
171
+ # Configuración básica de Redis
172
+ host: ENV['REDIS_HOST'] || 'localhost',
173
+ port: ENV['REDIS_PORT']&.to_i || 6379,
174
+ password: ENV['REDIS_PASSWORD'],
175
+ db: ENV['REDIS_DB']&.to_i || 0,
176
+
177
+ # Configuración TLS para conexiones seguras
178
+ tls: ENV['REDIS_TLS'] == 'true',
179
+ ca_cert_path: ENV['REDIS_CA_CERT_PATH'],
180
+ ca_cert_name: ENV['REDIS_CA_CERT_NAME']
174
181
  },
175
182
  enable_user_data_retrieval: true
176
183
  )
177
184
 
178
- # Usar inmediatamente
185
+ # Inicializar conexiones (incluye Redis)
186
+ validator.initialize!
187
+
188
+ # Usar inmediatamente con validación enriquecida
179
189
  result = validator.validate_token_enriched(token)
190
+
191
+ if result[:valid]
192
+ puts "✅ Token válido con datos enriquecidos:"
193
+ puts "Usuario: #{result[:sub]}"
194
+ puts "Permisos: #{result[:user_permissions]}"
195
+ puts "Organizaciones: #{result[:user_organizations]}"
196
+ puts "Aplicaciones: #{result[:applications]}"
197
+ else
198
+ puts "❌ Token inválido: #{result[:error]}"
199
+ end
180
200
  ```
181
201
 
182
202
  ### Manejo Mejorado de Errores (Nuevo v0.3.0)
@@ -420,6 +420,14 @@ module JwtAuthCognito
420
420
 
421
421
  return { valid: true } unless app_id
422
422
 
423
+ # Check API key access to the application using existing logic
424
+ api_key_data_symbolized = api_key_data.transform_keys(&:to_sym)
425
+ return { valid: false, error: "API key does not have access to application #{app_id}" } unless @api_key_validator.can_access_app?(api_key_data_symbolized, app_id)
426
+
427
+ # System API keys can access any application (bypass user validation)
428
+ return { valid: true } if api_key_data['scope'] == 'system'
429
+
430
+ # For non-system API keys, verify user has access to the application
423
431
  user_id = payload['sub']
424
432
  return { valid: false, error: 'Token missing user ID (sub claim)' } unless user_id
425
433
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JwtAuthCognito
4
- VERSION = '1.0.0-beta.1'
4
+ VERSION = '1.0.0-beta.3'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt_auth_cognito
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre.beta.1
4
+ version: 1.0.0.pre.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Optimal
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-09-15 00:00:00.000000000 Z
11
+ date: 2025-09-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-ssm