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 +4 -4
- data/.rubocop.yml +3 -0
- data/CHANGELOG.md +19 -0
- data/CLAUDE.md +51 -1
- data/README.md +25 -5
- data/lib/jwt_auth_cognito/jwt_validator.rb +8 -0
- data/lib/jwt_auth_cognito/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87913fe629cb36042e7d267bbb0cf3a814a8eb1289971a7192f600be8cf781b3
|
4
|
+
data.tar.gz: fe5b1f73de56acc80cc5f646a095093436255ee3b857534d6f5db2b0c34c2274
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41826e498618bd98a002e66a4f015610249645a15652528b540545114af8d8336c52f6186edc9a85dcd23159798ed6fdbd8f3038073704ef5fa9c61ec03ed0cf
|
7
|
+
data.tar.gz: 643d331d2b80d775d7011f86d1a76614425064d36e0513dc50e18a3a96fb1757c71a13303690d017743d70c1c783c60bd532c060f6b4299c64145855cb8eb98b
|
data/.rubocop.yml
CHANGED
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
|
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
|
-
|
172
|
-
|
173
|
-
|
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
|
-
#
|
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
|
|
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.
|
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-
|
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
|