class Grape::OAuth2::Generators::Authorization

OAuth2 Authorization generator class. Processes the request and builds the response.

Public Class Methods

generate_for(env) { |request, response| ... } click to toggle source

Generates Authorization Response based on the request.

@return [Grape::OAuth2::Responses::Authorization] response

# File lib/grape_oauth2/generators/authorization.rb, line 12
def generate_for(env, &_block)
  authorization = Rack::OAuth2::Server::Authorize.new do |request, response|
    if block_given?
      yield request, response
    else
      execute_default(request, response)
    end
  end

  Grape::OAuth2::Responses::Authorization.new(authorization.call(env))
rescue Rack::OAuth2::Server::Authorize::BadRequest => error
  error_response(error)
end

Private Class Methods

error_response(error) click to toggle source
# File lib/grape_oauth2/generators/authorization.rb, line 28
def error_response(error)
  response = Rack::Response.new
  response.status = error.status
  response.header['Content-Type'] = 'application/json'
  response.write(JSON.dump(Rack::OAuth2::Util.compact_hash(error.protocol_params)))

  Grape::OAuth2::Responses::Authorization.new(response.finish)
end
execute_default(request, response) click to toggle source
# File lib/grape_oauth2/generators/authorization.rb, line 37
def execute_default(request, response)
  Grape::OAuth2::Strategies::AuthorizationCode.process(request, response)
end