module GrapeOnRails::Authenticator
Attributes
current_user[RW]
Public Instance Methods
authenticate!()
click to toggle source
# File lib/grape_on_rails/authenticator.rb, line 7 def authenticate! @current_user = GoR.models.user_token.constantize .find_token!(token_on_header)&.public_send(GoR.models.user.downcase) raise APIError::Unauthenticated unless current_user end
refresh_token!()
click to toggle source
# File lib/grape_on_rails/authenticator.rb, line 13 def refresh_token! token = GoR.models.user_token.constantize.find_by refresh_token: token_on_header token ? token.renew! : raise(APIError::Unauthenticated) token end
token_on_header()
click to toggle source
# File lib/grape_on_rails/authenticator.rb, line 19 def token_on_header auth_header = request.headers[GoR.access_token_header] auth_header&.scan(/^#{GoR.access_token_value_prefix} (.+)$/i)&.flatten&.[]0 end