class Grape::OAuth2::Generators::Token
OAuth2
Token
generator class. Processes the request by required Grant Type and builds the response.
Constants
- STRATEGY_CLASSES
Grant type =>
OAuth2
strategy class
Public Class Methods
generate_for(env) { |request, response| ... }
click to toggle source
Generates Token
Response based on the request.
@return [Grape::OAuth2::Responses::Token] response
# File lib/grape_oauth2/generators/token.rb, line 19 def generate_for(env, &_block) token = Rack::OAuth2::Server::Token.new do |request, response| request.unsupported_grant_type! unless allowed_grants.include?(request.grant_type.to_s) if block_given? yield request, response else execute_default(request, response) end end Grape::OAuth2::Responses::Token.new(token.call(env)) end
Protected Class Methods
execute_default(request, response)
click to toggle source
Runs default Grape::OAuth2
functionality for Token
endpoint. In common it authenticates client (or/and any other objects) and grants the Access Token
or Auth Code.
@param request [Rack::Request] request object @param response [Rack::Response] response object
# File lib/grape_oauth2/generators/token.rb, line 42 def execute_default(request, response) strategy = find_strategy(request.grant_type) || request.invalid_grant! response.access_token = strategy.process(request) end
find_strategy(grant_type)
click to toggle source
Returns Grape::OAuth2
strategy class by Grant Type.
@param grant_type [Symbol]
grant type value
@return [Password, ClientCredentials, RefreshToken]
strategy class
# File lib/grape_oauth2/generators/token.rb, line 55 def find_strategy(grant_type) STRATEGY_CLASSES[grant_type] end