Module: ApiGuard::JwtAuth::BlacklistToken
- Defined in:
- lib/api_guard/jwt_auth/blacklist_token.rb
Overview
Common module for token blacklisting functionality
Instance Method Summary collapse
-
#blacklist_token ⇒ Object
Blacklist the current JWT token from future access.
-
#blacklisted?(resource) ⇒ Boolean
Returns whether the JWT token is blacklisted or not.
- #blacklisted_token_association(resource) ⇒ Object
- #blacklisted_tokens_for(resource) ⇒ Object
- #token_blacklisting_enabled?(resource) ⇒ Boolean
Instance Method Details
#blacklist_token ⇒ Object
Blacklist the current JWT token from future access
28 29 30 31 32 |
# File 'lib/api_guard/jwt_auth/blacklist_token.rb', line 28 def blacklist_token return unless token_blacklisting_enabled?(current_resource) blacklisted_tokens_for(current_resource).create(token: @token, expire_at: Time.at(@decoded_token[:exp]).utc) end |
#blacklisted?(resource) ⇒ Boolean
Returns whether the JWT token is blacklisted or not
21 22 23 24 25 |
# File 'lib/api_guard/jwt_auth/blacklist_token.rb', line 21 def blacklisted?(resource) return false unless token_blacklisting_enabled?(resource) blacklisted_tokens_for(resource).exists?(token: @token) end |
#blacklisted_token_association(resource) ⇒ Object
7 8 9 |
# File 'lib/api_guard/jwt_auth/blacklist_token.rb', line 7 def blacklisted_token_association(resource) resource.class.blacklisted_token_association end |
#blacklisted_tokens_for(resource) ⇒ Object
15 16 17 18 |
# File 'lib/api_guard/jwt_auth/blacklist_token.rb', line 15 def blacklisted_tokens_for(resource) blacklisted_token_association = blacklisted_token_association(resource) resource.send(blacklisted_token_association) end |
#token_blacklisting_enabled?(resource) ⇒ Boolean
11 12 13 |
# File 'lib/api_guard/jwt_auth/blacklist_token.rb', line 11 def token_blacklisting_enabled?(resource) blacklisted_token_association(resource).present? end |