Class: PDND::JWTGenerator
- Inherits:
-
Object
- Object
- PDND::JWTGenerator
- Defined in:
- lib/pdnd-ruby-client/jwt_generator.rb
Overview
Classe responsabile della generazione di token JWT per autenticare le richieste verso l'API PDND. Firma il token con una chiave RSA (RS256) e lo invia al server OAuth2 per ottenere un access token.
JWT Generator collapse
-
#assertion ⇒ Object
Returns the value of attribute assertion.
-
#audience ⇒ Object
Returns the value of attribute audience.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#config ⇒ Object
Returns the value of attribute config.
-
#debug ⇒ Object
Returns the value of attribute debug.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#env ⇒ Object
Returns the value of attribute env.
-
#issuer ⇒ Object
Returns the value of attribute issuer.
-
#kid ⇒ Object
Returns the value of attribute kid.
-
#priv_key ⇒ Object
Returns the value of attribute priv_key.
-
#priv_key_path ⇒ Object
Returns the value of attribute priv_key_path.
-
#purpose_id ⇒ Object
Returns the value of attribute purpose_id.
-
#token ⇒ Object
Returns the value of attribute token.
-
#token_exp ⇒ Object
Returns the value of attribute token_exp.
JWT Generator collapse
-
#generate_token ⇒ Array<String>
Token di accesso e data di scadenza formattata.
-
#initialize(config, env = 'produzione') ⇒ JWTGenerator
constructor
A new instance of JWTGenerator.
Constructor Details
#initialize(config, env = 'produzione') ⇒ JWTGenerator
Returns a new instance of JWTGenerator.
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 35 def initialize(config, env = 'produzione') @config = config @env = env @assertion = '' @token = '' @token_exp = '' @debug = false assign_config_values(config) configure_environment end |
Instance Attribute Details
#assertion ⇒ Object
Returns the value of attribute assertion.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def assertion @assertion end |
#audience ⇒ Object
Returns the value of attribute audience.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def audience @audience end |
#client_id ⇒ Object
Returns the value of attribute client_id.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def client_id @client_id end |
#config ⇒ Object
Returns the value of attribute config.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def config @config end |
#debug ⇒ Object
Returns the value of attribute debug.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def debug @debug end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def endpoint @endpoint end |
#env ⇒ Object
Returns the value of attribute env.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def env @env end |
#issuer ⇒ Object
Returns the value of attribute issuer.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def issuer @issuer end |
#kid ⇒ Object
Returns the value of attribute kid.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def kid @kid end |
#priv_key ⇒ Object
Returns the value of attribute priv_key.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def priv_key @priv_key end |
#priv_key_path ⇒ Object
Returns the value of attribute priv_key_path.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def priv_key_path @priv_key_path end |
#purpose_id ⇒ Object
Returns the value of attribute purpose_id.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def purpose_id @purpose_id end |
#token ⇒ Object
Returns the value of attribute token.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def token @token end |
#token_exp ⇒ Object
Returns the value of attribute token_exp.
29 30 31 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 29 def token_exp @token_exp end |
Instance Method Details
#generate_token ⇒ Array<String>
Returns Token di accesso e data di scadenza formattata.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/pdnd-ruby-client/jwt_generator.rb', line 48 def generate_token private_key = load_private_key @assertion = JWT.encode(build_payload, private_key, 'RS256', build_header) debug_log('🔐 Token JWT generato', @assertion) response_body = post_assertion @token = response_body['access_token'] @token_exp = format_expiration(response_body['expires_in']) debug_log('✅ Token generato', @token) debug_log('✅ Token scadenza', @token_exp) [@token, @token_exp] end |