Module: ApiGuard::JwtAuth::RefreshJwtToken
- Included in:
- Test::ControllerHelper
- Defined in:
- lib/api_guard/jwt_auth/refresh_jwt_token.rb
Overview
Common module for refresh token functionality
Class Method Summary collapse
- .destroy_all_refresh_tokens(resource) ⇒ Object
- .find_refresh_token_of(resource, refresh_token) ⇒ Object
-
.new_refresh_token(resource) ⇒ Object
Create a new refresh_token for the current resource.
- .refresh_token_association(resource) ⇒ Object
- .refresh_token_enabled?(resource) ⇒ Boolean
- .refresh_tokens_for(resource) ⇒ Object
-
.uniq_refresh_token(resource) ⇒ Object
Generate and return unique refresh token for the resource.
Class Method Details
.destroy_all_refresh_tokens(resource) ⇒ Object
39 40 41 42 43 |
# File 'lib/api_guard/jwt_auth/refresh_jwt_token.rb', line 39 def self.destroy_all_refresh_tokens(resource) return unless refresh_token_enabled?(resource) refresh_tokens_for(resource).destroy_all end |
.find_refresh_token_of(resource, refresh_token) ⇒ Object
20 21 22 |
# File 'lib/api_guard/jwt_auth/refresh_jwt_token.rb', line 20 def self.find_refresh_token_of(resource, refresh_token) refresh_tokens_for(resource).find_by_token(refresh_token) end |
.new_refresh_token(resource) ⇒ Object
Create a new refresh_token for the current resource
33 34 35 36 37 |
# File 'lib/api_guard/jwt_auth/refresh_jwt_token.rb', line 33 def self.new_refresh_token(resource) return unless refresh_token_enabled?(resource) refresh_tokens_for(resource).create(token: uniq_refresh_token(resource)).token end |
.refresh_token_association(resource) ⇒ Object
7 8 9 |
# File 'lib/api_guard/jwt_auth/refresh_jwt_token.rb', line 7 def self.refresh_token_association(resource) resource.class.refresh_token_association end |
.refresh_token_enabled?(resource) ⇒ Boolean
11 12 13 |
# File 'lib/api_guard/jwt_auth/refresh_jwt_token.rb', line 11 def self.refresh_token_enabled?(resource) refresh_token_association(resource).present? end |
.refresh_tokens_for(resource) ⇒ Object
15 16 17 18 |
# File 'lib/api_guard/jwt_auth/refresh_jwt_token.rb', line 15 def self.refresh_tokens_for(resource) refresh_token_association = refresh_token_association(resource) resource.send(refresh_token_association) end |
.uniq_refresh_token(resource) ⇒ Object
Generate and return unique refresh token for the resource
25 26 27 28 29 30 |
# File 'lib/api_guard/jwt_auth/refresh_jwt_token.rb', line 25 def self.uniq_refresh_token(resource) loop do random_token = SecureRandom.urlsafe_base64 return random_token unless refresh_tokens_for(resource).exists?(token: random_token) end end |