Class: Grape::OAuth2::Generators::Authorization

Inherits:
Base
  • Object
show all
Defined in:
lib/grape_oauth2/generators/authorization.rb

Overview

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

Class Method Summary collapse

Methods inherited from Base

allowed_grants, config

Class Method Details

.generate_for(env, &_block) ⇒ Grape::OAuth2::Responses::Authorization

Generates Authorization Response based on the request.



12
13
14
15
16
17
18
19
20
21
22
23
24
# 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