Module: Grape::OAuth2::Helpers::AccessTokenHelpers
- Extended by:
- API::Helpers
- Defined in:
- lib/grape_oauth2/helpers/access_token_helpers.rb
Overview
Set of Grape OAuth2 helpers.
Instance Method Summary collapse
-
#access_token_required!(*scopes) ⇒ Object
Adds OAuth2 Access Token protection for Grape routes.
-
#current_access_token ⇒ Object
Returns Access Token instance found by access_token value passed with the request.
-
#current_resource_owner ⇒ Object
Returns Resource Owner from the Access Token found by access_token value passed with the request.
Instance Method Details
#access_token_required!(*scopes) ⇒ Object
Adds OAuth2 Access Token protection for Grape routes.
18 19 20 21 22 23 24 |
# File 'lib/grape_oauth2/helpers/access_token_helpers.rb', line 18 def access_token_required!(*scopes) endpoint_scopes = env['api.endpoint'].[:route_options][:scopes] required_scopes = endpoint_scopes.presence || scopes raise Rack::OAuth2::Server::Resource::Bearer::Unauthorized if current_access_token.nil? raise Rack::OAuth2::Server::Resource::Bearer::Forbidden unless valid_access_token?(required_scopes) end |
#current_access_token ⇒ Object
Returns Access Token instance found by access_token value passed with the request.
34 35 36 |
# File 'lib/grape_oauth2/helpers/access_token_helpers.rb', line 34 def current_access_token @_current_access_token ||= request.env[Rack::OAuth2::Server::Resource::ACCESS_TOKEN] end |
#current_resource_owner ⇒ Object
Returns Resource Owner from the Access Token found by access_token value passed with the request.
28 29 30 |
# File 'lib/grape_oauth2/helpers/access_token_helpers.rb', line 28 def current_resource_owner @_current_resource_owner ||= current_access_token.resource_owner end |