Module: GrapeOnRails::Authenticator
- Includes:
- Support
- Defined in:
- lib/grape_on_rails/authenticator.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Support
#class_name, #gor_translate
Instance Attribute Details
#current_user ⇒ Object
Returns the value of attribute current_user.
5
6
7
|
# File 'lib/grape_on_rails/authenticator.rb', line 5
def current_user
@current_user
end
|
Instance Method Details
#authenticate! ⇒ Object
7
8
9
10
11
|
# File 'lib/grape_on_rails/authenticator.rb', line 7
def authenticate!
@current_user = GoR.models.user_token.constantize
.find_token!()&.public_send(GoR.models.user.downcase)
raise APIError::Unauthenticated unless current_user
end
|
#refresh_token! ⇒ Object
13
14
15
16
17
|
# File 'lib/grape_on_rails/authenticator.rb', line 13
def refresh_token!
token = GoR.models.user_token.constantize.find_by refresh_token:
token ? token.renew! : raise(APIError::Unauthenticated)
token
end
|
19
20
21
22
|
# File 'lib/grape_on_rails/authenticator.rb', line 19
def
= request.[GoR.]
&.scan(/^#{GoR.access_token_value_prefix} (.+)$/i)&.flatten&.[]0
end
|