Class: AuthRails::Services::JwtService
- Inherits:
-
Object
- Object
- AuthRails::Services::JwtService
- Defined in:
- lib/auth_rails/services/jwt_service.rb
Class Method Summary collapse
- .gen_token(payload:, exp: nil, secret_key: nil, algorithm: nil, jti: nil) ⇒ Object
- .verify_token(token:, secret_key: nil, algorithm: nil) ⇒ Object
Class Method Details
.gen_token(payload:, exp: nil, secret_key: nil, algorithm: nil, jti: nil) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/auth_rails/services/jwt_service.rb', line 7 def gen_token(payload:, exp: nil, secret_key: nil, algorithm: nil, jti: nil) exp ||= Configuration::Jwt::AccessToken.exp.to_i JWT.encode( (payload || {}).merge(jti: jti || SecureRandom.hex(20)), secret_key, algo(algorithm), { exp: exp.to_i } ) end |
.verify_token(token:, secret_key: nil, algorithm: nil) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/auth_rails/services/jwt_service.rb', line 20 def verify_token(token:, secret_key: nil, algorithm: nil) JWT.decode( token, secret_key, true, { algorithm: algo(algorithm) } )[0].deep_symbolize_keys rescue StandardError {} end |