Class: RailsIam::Authentication::JwtEncoder
- Inherits:
-
RailsIamService
- Object
- ApplicationService
- RailsIamService
- RailsIam::Authentication::JwtEncoder
- Defined in:
- app/services/rails_iam/authentication/jwt_encoder.rb
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(user, extra_claims = {}, headers = {}) ⇒ JwtEncoder
constructor
A new instance of JwtEncoder.
Methods inherited from RailsIamService
Methods included from ConfigLoader
#authentication_strategies, #authorization_rule_error, #cookie_options, #jwt_algorithm, #jwt_audience, #jwt_expiry, #jwt_issuer, #jwt_secret_key, #refresh_token_transport, #session_strategy, #user_class
Constructor Details
#initialize(user, extra_claims = {}, headers = {}) ⇒ JwtEncoder
Returns a new instance of JwtEncoder.
6 7 8 9 10 11 |
# File 'app/services/rails_iam/authentication/jwt_encoder.rb', line 6 def initialize(user, extra_claims = {}, headers = {}) super() @user = user @extra_claims = extra_claims @headers = headers end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'app/services/rails_iam/authentication/jwt_encoder.rb', line 13 def call if jwt_secret_key.blank? raise RailsIam::Authentication::Exceptions::AuthenticationError, "Token generation failed due to a missing cryptographic configuration/jwt secret." end JWT.encode(payload, jwt_secret_key, jwt_algorithm, headers) rescue JWT::EncodeError => e raise RailsIam::Authentication::Exceptions::AuthenticationError e. end |