Class: AuthRails::Strategies::AllowedTokenStrategy
- Inherits:
-
BaseStrategy
- Object
- BaseStrategy
- AuthRails::Strategies::AllowedTokenStrategy
- Defined in:
- lib/auth_rails/strategies/allowed_token_strategy.rb
Class Method Summary collapse
- .gen_token(resource:, payload:, exp: nil, secret_key: nil, algorithm: nil) ⇒ Object
- .retrieve_resource(payload:) ⇒ Object
Class Method Details
.gen_token(resource:, payload:, exp: nil, secret_key: nil, algorithm: nil) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/auth_rails/strategies/allowed_token_strategy.rb', line 17 def gen_token(resource:, payload:, exp: nil, secret_key: nil, algorithm: nil) jti = SecureRandom.hex(20) resource.allowed_tokens .create!( jti: jti, aud: payload[:aud], exp: Time.zone.at(exp) ) super( jti: jti, exp: exp, payload: payload, algorithm: algorithm, secret_key: secret_key ) end |
.retrieve_resource(payload:) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/auth_rails/strategies/allowed_token_strategy.rb', line 7 def retrieve_resource(payload:) symbolized_payload = payload.symbolize_keys AuthRails.resource_class .joins(:allowed_tokens) .where(allowed_tokens: symbolized_payload.slice(:jti, :aud)) .where('allowed_tokens.exp > ?', Time.current) .find_by(AuthRails.identifier_name => symbolized_payload[:sub]) end |