jwt_auth_cognito 0.1.0 → 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.
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  namespace :jwt_auth_cognito do
4
- desc "Genera archivo de configuración para jwt_auth_cognito"
4
+ desc 'Genera archivo de configuración para jwt_auth_cognito'
5
5
  task :install do
6
- puts "🚀 Instalando jwt_auth_cognito..."
7
-
6
+ puts '🚀 Instalando jwt_auth_cognito...'
7
+
8
8
  # Verificar si estamos en una aplicación Rails
9
9
  unless defined?(Rails)
10
- puts "❌ Error: Este comando debe ejecutarse desde una aplicación Rails"
10
+ puts '❌ Error: Este comando debe ejecutarse desde una aplicación Rails'
11
11
  exit 1
12
12
  end
13
13
 
@@ -20,10 +20,10 @@ namespace :jwt_auth_cognito do
20
20
  # Generar archivo de configuración
21
21
  if File.exist?(config_file)
22
22
  print "El archivo #{config_file} ya existe. ¿Sobrescribir? (y/N): "
23
- response = STDIN.gets.chomp.downcase
24
-
23
+ response = $stdin.gets.chomp.downcase
24
+
25
25
  unless %w[y yes sí si].include?(response)
26
- puts "⏭️ Instalación cancelada"
26
+ puts '⏭️ Instalación cancelada'
27
27
  exit 0
28
28
  end
29
29
  end
@@ -36,107 +36,106 @@ namespace :jwt_auth_cognito do
36
36
 
37
37
  # Generar/actualizar .env.example
38
38
  env_content = generate_env_content
39
-
39
+
40
40
  if File.exist?(env_file)
41
41
  existing_content = File.read(env_file)
42
- unless existing_content.include?('COGNITO_USER_POOL_ID')
43
- File.write(env_file, existing_content + "\n" + env_content)
44
- puts "✅ Variables agregadas a .env.example"
42
+ if existing_content.include?('COGNITO_USER_POOL_ID')
43
+ puts 'ℹ️ Variables ya existen en .env.example'
45
44
  else
46
- puts "ℹ️ Variables ya existen en .env.example"
45
+ File.write(env_file, "#{existing_content}\n#{env_content}")
46
+ puts '✅ Variables agregadas a .env.example'
47
47
  end
48
48
  else
49
49
  File.write(env_file, env_content)
50
- puts "✅ Archivo .env.example creado"
50
+ puts '✅ Archivo .env.example creado'
51
51
  end
52
52
 
53
53
  show_next_steps
54
54
  end
55
55
 
56
- desc "Muestra la configuración actual de jwt_auth_cognito"
56
+ desc 'Muestra la configuración actual de jwt_auth_cognito'
57
57
  task :config do
58
- puts "📋 Configuración actual de jwt_auth_cognito:"
59
- puts "=" * 50
60
-
58
+ puts '📋 Configuración actual de jwt_auth_cognito:'
59
+ puts '=' * 50
60
+
61
61
  config = JwtAuthCognito.configuration
62
-
63
- puts "🏛️ AWS Cognito:"
62
+
63
+ puts '🏛️ AWS Cognito:'
64
64
  puts " Region: #{config.cognito_region || '❌ NO CONFIGURADO'}"
65
65
  puts " User Pool ID: #{config.cognito_user_pool_id || '❌ NO CONFIGURADO'}"
66
66
  puts " Client ID: #{config.cognito_client_id || '❌ NO CONFIGURADO'}"
67
67
  puts " Client Secret: #{config.has_client_secret? ? '✅ CONFIGURADO' : '⚠️ NO CONFIGURADO'}"
68
-
68
+
69
69
  puts "\n🗄️ Redis:"
70
70
  puts " Host: #{config.redis_host}"
71
71
  puts " Puerto: #{config.redis_port}"
72
72
  puts " Base de datos: #{config.redis_db}"
73
73
  puts " TLS: #{config.redis_ssl ? '✅ HABILITADO' : '❌ DESHABILITADO'}"
74
74
  puts " Password: #{config.redis_password ? '✅ CONFIGURADO' : '❌ NO CONFIGURADO'}"
75
-
75
+
76
76
  puts "\n⚙️ Configuración:"
77
77
  puts " Modo de validación: #{config.validation_mode}"
78
78
  puts " Cache JWKS TTL: #{config.jwks_cache_ttl}s"
79
79
  puts " Entorno: #{config.environment}"
80
-
80
+
81
81
  puts "\n🔍 URLs:"
82
82
  begin
83
83
  puts " JWKS URL: #{config.jwks_url}"
84
84
  puts " Cognito Issuer: #{config.cognito_issuer}"
85
- rescue => e
85
+ rescue StandardError => e
86
86
  puts " ❌ Error generando URLs: #{e.message}"
87
87
  end
88
88
  end
89
89
 
90
- desc "Prueba la conexión a Redis"
90
+ desc 'Prueba la conexión a Redis'
91
91
  task :test_redis do
92
- puts "🔧 Probando conexión a Redis..."
93
-
92
+ puts '🔧 Probando conexión a Redis...'
93
+
94
94
  begin
95
95
  redis_service = JwtAuthCognito::RedisService.new
96
96
  redis_service.send(:connect_redis)
97
- puts "✅ Conexión a Redis exitosa"
98
- rescue => e
97
+ puts '✅ Conexión a Redis exitosa'
98
+ rescue StandardError => e
99
99
  puts "❌ Error conectando a Redis: #{e.message}"
100
100
  puts "\n💡 Verifica tu configuración de Redis en las variables de entorno"
101
101
  end
102
102
  end
103
103
 
104
- desc "Prueba la configuración de Cognito"
104
+ desc 'Prueba la configuración de Cognito'
105
105
  task :test_cognito do
106
- puts "🔧 Probando configuración de Cognito..."
107
-
106
+ puts '🔧 Probando configuración de Cognito...'
107
+
108
108
  config = JwtAuthCognito.configuration
109
-
109
+
110
110
  begin
111
111
  config.validate!
112
- puts "✅ Configuración básica de Cognito válida"
113
-
112
+ puts '✅ Configuración básica de Cognito válida'
113
+
114
114
  # Probar JWKS
115
115
  jwks_service = JwtAuthCognito::JwksService.new
116
116
  jwks_service.send(:fetch_jwks)
117
- puts "✅ Conexión a JWKS exitosa"
118
-
119
- rescue => e
117
+ puts '✅ Conexión a JWKS exitosa'
118
+ rescue StandardError => e
120
119
  puts "❌ Error en configuración de Cognito: #{e.message}"
121
120
  puts "\n💡 Verifica tus variables de entorno de Cognito"
122
121
  end
123
122
  end
124
123
 
125
- desc "Limpia todos los tokens de la blacklist"
124
+ desc 'Limpia todos los tokens de la blacklist'
126
125
  task :clear_blacklist do
127
- print "⚠️ ¿Estás seguro de que quieres limpiar toda la blacklist? (y/N): "
128
- response = STDIN.gets.chomp.downcase
129
-
126
+ print '⚠️ ¿Estás seguro de que quieres limpiar toda la blacklist? (y/N): '
127
+ response = $stdin.gets.chomp.downcase
128
+
130
129
  if %w[y yes sí si].include?(response)
131
130
  begin
132
131
  blacklist_service = JwtAuthCognito::TokenBlacklistService.new
133
132
  count = blacklist_service.clear_all_blacklisted_tokens
134
133
  puts "✅ #{count} tokens eliminados de la blacklist"
135
- rescue => e
134
+ rescue StandardError => e
136
135
  puts "❌ Error limpiando blacklist: #{e.message}"
137
136
  end
138
137
  else
139
- puts "⏭️ Operación cancelada"
138
+ puts '⏭️ Operación cancelada'
140
139
  end
141
140
  end
142
141
 
@@ -144,7 +143,7 @@ namespace :jwt_auth_cognito do
144
143
 
145
144
  def generate_config_content
146
145
  has_redis_config = defined?(Rails) && File.exist?(Rails.root.join('config', 'redis.yml'))
147
-
146
+
148
147
  <<~CONFIG
149
148
  # frozen_string_literal: true
150
149
 
@@ -155,16 +154,16 @@ namespace :jwt_auth_cognito do
155
154
  # =============================================================================
156
155
  # CONFIGURACIÓN DE AWS COGNITO
157
156
  # =============================================================================
158
-
157
+ #{' '}
159
158
  # User Pool ID de tu Cognito (requerido)
160
159
  config.cognito_user_pool_id = ENV['COGNITO_USER_POOL_ID']
161
-
160
+ #{' '}
162
161
  # Región de AWS donde está tu Cognito (requerido)
163
162
  config.cognito_region = ENV['COGNITO_REGION'] || ENV['AWS_REGION'] || 'us-east-1'
164
-
163
+ #{' '}
165
164
  # Client ID de tu aplicación en Cognito (requerido para validación de audiencia)
166
165
  config.cognito_client_id = ENV['COGNITO_CLIENT_ID']
167
-
166
+ #{' '}
168
167
  # Client Secret de tu aplicación en Cognito (opcional, para mayor seguridad)
169
168
  # Si tu User Pool App Client está configurado con client secret, esto es requerido
170
169
  config.cognito_client_secret = ENV['COGNITO_CLIENT_SECRET']
@@ -172,9 +171,9 @@ namespace :jwt_auth_cognito do
172
171
  # =============================================================================
173
172
  # CONFIGURACIÓN DE REDIS (para blacklist de tokens)
174
173
  # =============================================================================
175
-
174
+ #{' '}
176
175
  #{redis_config_section(has_redis_config)}
177
-
176
+ #{' '}
178
177
  # Configuración de timeouts para Redis
179
178
  config.redis_timeout = ENV['REDIS_TIMEOUT']&.to_i || 5
180
179
  config.redis_connect_timeout = ENV['REDIS_CONNECT_TIMEOUT']&.to_i || 10
@@ -183,11 +182,11 @@ namespace :jwt_auth_cognito do
183
182
  # =============================================================================
184
183
  # CONFIGURACIÓN TLS PARA REDIS (PRODUCCIÓN)
185
184
  # =============================================================================
186
-
185
+ #{' '}
187
186
  # Configuración de certificados CA para Redis TLS
188
187
  config.redis_ca_cert_path = ENV['REDIS_CA_CERT_PATH']
189
188
  config.redis_ca_cert_name = ENV['REDIS_CA_CERT_NAME']
190
-
189
+ #{' '}
191
190
  # Control de versiones TLS
192
191
  config.redis_tls_min_version = ENV['REDIS_TLS_MIN_VERSION'] || 'TLSv1.2'
193
192
  config.redis_tls_max_version = ENV['REDIS_TLS_MAX_VERSION'] || 'TLSv1.3'
@@ -196,10 +195,10 @@ namespace :jwt_auth_cognito do
196
195
  # =============================================================================
197
196
  # CONFIGURACIÓN DE VALIDACIÓN
198
197
  # =============================================================================
199
-
198
+ #{' '}
200
199
  # Modo de validación: :secure (producción) o :basic (desarrollo)
201
200
  config.validation_mode = Rails.env.production? ? :secure : :basic
202
-
201
+ #{' '}
203
202
  # Tiempo de cache para claves JWKS (en segundos)
204
203
  config.jwks_cache_ttl = ENV['JWKS_CACHE_TTL']&.to_i || 3600 # 1 hora
205
204
  end
@@ -265,26 +264,26 @@ namespace :jwt_auth_cognito do
265
264
  end
266
265
 
267
266
  def show_next_steps
268
- puts "\n" + "=" * 60
269
- puts "🎉 ¡Instalación de jwt_auth_cognito completada!"
270
- puts "=" * 60
267
+ puts "\n#{'=' * 60}"
268
+ puts '🎉 ¡Instalación de jwt_auth_cognito completada!'
269
+ puts '=' * 60
271
270
  puts "\n📋 PRÓXIMOS PASOS:"
272
271
  puts "\n1. 🔧 Configura las variables de entorno:"
273
- puts " - Edita .env (si usas dotenv) o configura variables del sistema"
274
- puts " - Como mínimo configura: COGNITO_USER_POOL_ID, COGNITO_REGION, COGNITO_CLIENT_ID"
275
-
272
+ puts ' - Edita .env (si usas dotenv) o configura variables del sistema'
273
+ puts ' - Como mínimo configura: COGNITO_USER_POOL_ID, COGNITO_REGION, COGNITO_CLIENT_ID'
274
+
276
275
  puts "\n2. 🧪 Prueba la configuración:"
277
- puts " rake jwt_auth_cognito:config # Ver configuración actual"
278
- puts " rake jwt_auth_cognito:test_cognito # Probar Cognito"
279
- puts " rake jwt_auth_cognito:test_redis # Probar Redis"
280
-
276
+ puts ' rake jwt_auth_cognito:config # Ver configuración actual'
277
+ puts ' rake jwt_auth_cognito:test_cognito # Probar Cognito'
278
+ puts ' rake jwt_auth_cognito:test_redis # Probar Redis'
279
+
281
280
  puts "\n3. 🚀 Reinicia tu aplicación Rails"
282
-
281
+
283
282
  puts "\n4. 📖 Usa la gema en tu código:"
284
- puts " validator = JwtAuthCognito::JwtValidator.new"
285
- puts " result = validator.validate_token(jwt_token)"
286
-
283
+ puts ' validator = JwtAuthCognito::JwtValidator.new'
284
+ puts ' result = validator.validate_token(jwt_token)'
285
+
287
286
  puts "\n💡 Para más ejemplos, revisa el README de la gema"
288
- puts "=" * 60
287
+ puts '=' * 60
289
288
  end
290
- end
289
+ end
metadata CHANGED
@@ -1,17 +1,31 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jwt_auth_cognito
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - The Optimal
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2025-06-16 00:00:00.000000000 Z
11
+ date: 2025-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: jwt
14
+ name: aws-sdk-ssm
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - "~>"
@@ -25,25 +39,19 @@ dependencies:
25
39
  - !ruby/object:Gem::Version
26
40
  version: '2.0'
27
41
  - !ruby/object:Gem::Dependency
28
- name: redis
42
+ name: jwt
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 4.2.5
34
- - - "<"
45
+ - - "~>"
35
46
  - !ruby/object:Gem::Version
36
- version: '6.0'
47
+ version: '2.0'
37
48
  type: :runtime
38
49
  prerelease: false
39
50
  version_requirements: !ruby/object:Gem::Requirement
40
51
  requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- version: 4.2.5
44
- - - "<"
52
+ - - "~>"
45
53
  - !ruby/object:Gem::Version
46
- version: '6.0'
54
+ version: '2.0'
47
55
  - !ruby/object:Gem::Dependency
48
56
  name: openssl
49
57
  requirement: !ruby/object:Gem::Requirement
@@ -59,21 +67,27 @@ dependencies:
59
67
  - !ruby/object:Gem::Version
60
68
  version: 2.1.0
61
69
  - !ruby/object:Gem::Dependency
62
- name: json
70
+ name: redis
63
71
  requirement: !ruby/object:Gem::Requirement
64
72
  requirements:
65
- - - "~>"
73
+ - - ">="
66
74
  - !ruby/object:Gem::Version
67
- version: '2.0'
75
+ version: 4.2.5
76
+ - - "<"
77
+ - !ruby/object:Gem::Version
78
+ version: '6.0'
68
79
  type: :runtime
69
80
  prerelease: false
70
81
  version_requirements: !ruby/object:Gem::Requirement
71
82
  requirements:
72
- - - "~>"
83
+ - - ">="
73
84
  - !ruby/object:Gem::Version
74
- version: '2.0'
85
+ version: 4.2.5
86
+ - - "<"
87
+ - !ruby/object:Gem::Version
88
+ version: '6.0'
75
89
  - !ruby/object:Gem::Dependency
76
- name: rspec
90
+ name: aws-sdk-core
77
91
  requirement: !ruby/object:Gem::Requirement
78
92
  requirements:
79
93
  - - "~>"
@@ -120,6 +134,20 @@ dependencies:
120
134
  - - "~>"
121
135
  - !ruby/object:Gem::Version
122
136
  version: '13.0'
137
+ - !ruby/object:Gem::Dependency
138
+ name: rspec
139
+ requirement: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - "~>"
142
+ - !ruby/object:Gem::Version
143
+ version: '3.0'
144
+ type: :development
145
+ prerelease: false
146
+ version_requirements: !ruby/object:Gem::Requirement
147
+ requirements:
148
+ - - "~>"
149
+ - !ruby/object:Gem::Version
150
+ version: '3.0'
123
151
  - !ruby/object:Gem::Dependency
124
152
  name: rubocop
125
153
  requirement: !ruby/object:Gem::Requirement
@@ -154,8 +182,13 @@ email:
154
182
  - contact@theoptimal.com
155
183
  executables: []
156
184
  extensions: []
157
- extra_rdoc_files: []
185
+ extra_rdoc_files:
186
+ - README.md
187
+ - CHANGELOG.md
188
+ - LICENSE.txt
158
189
  files:
190
+ - ".rubocop.yml"
191
+ - BITBUCKET-DEPLOYMENT.md
159
192
  - CHANGELOG.md
160
193
  - CLAUDE.md
161
194
  - Gemfile
@@ -163,16 +196,22 @@ files:
163
196
  - PUBLISH_GUIDE.md
164
197
  - README.md
165
198
  - Rakefile
199
+ - VERSIONING.md
200
+ - bitbucket-pipelines.yml
166
201
  - jwt_auth_cognito.gemspec
167
202
  - lib/generators/jwt_auth_cognito/install_generator.rb
168
203
  - lib/generators/jwt_auth_cognito/templates/jwt_auth_cognito.rb.erb
169
204
  - lib/jwt_auth_cognito.rb
205
+ - lib/jwt_auth_cognito/api_key_validator.rb
170
206
  - lib/jwt_auth_cognito/configuration.rb
207
+ - lib/jwt_auth_cognito/error_utils.rb
171
208
  - lib/jwt_auth_cognito/jwks_service.rb
172
209
  - lib/jwt_auth_cognito/jwt_validator.rb
173
210
  - lib/jwt_auth_cognito/railtie.rb
174
211
  - lib/jwt_auth_cognito/redis_service.rb
212
+ - lib/jwt_auth_cognito/ssm_service.rb
175
213
  - lib/jwt_auth_cognito/token_blacklist_service.rb
214
+ - lib/jwt_auth_cognito/user_data_service.rb
176
215
  - lib/jwt_auth_cognito/version.rb
177
216
  - lib/tasks/jwt_auth_cognito.rake
178
217
  homepage: https://github.com/theoptimal/jwt-auth-cognito
@@ -183,10 +222,12 @@ metadata:
183
222
  homepage_uri: https://github.com/theoptimal/jwt-auth-cognito
184
223
  source_code_uri: https://github.com/theoptimal/jwt-auth-cognito
185
224
  changelog_uri: https://github.com/theoptimal/jwt-auth-cognito/blob/main/CHANGELOG.md
186
- documentation_uri: https://github.com/theoptimal/jwt-auth-cognito/blob/main/README.md
225
+ documentation_uri: https://www.rubydoc.info/gems/jwt_auth_cognito
187
226
  bug_tracker_uri: https://github.com/theoptimal/jwt-auth-cognito/issues
188
- post_install_message:
189
- rdoc_options: []
227
+ rubygems_mfa_required: 'true'
228
+ post_install_message:
229
+ rdoc_options:
230
+ - "--charset=UTF-8"
190
231
  require_paths:
191
232
  - lib
192
233
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -200,8 +241,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
241
  - !ruby/object:Gem::Version
201
242
  version: '0'
202
243
  requirements: []
203
- rubygems_version: 3.1.6
204
- signing_key:
244
+ rubygems_version: 3.3.27
245
+ signing_key:
205
246
  specification_version: 4
206
247
  summary: Validación offline de JWT con AWS Cognito y blacklist Redis
207
248
  test_files: []