Class: Simple::OAuth2::Generators::Authorization

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

Overview

Authorization generator class Processes the request by required Response Type and builds the response

Class Method Summary collapse

Methods inherited from Base

allowed_grants, allowed_types, config

Class Method Details

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

Generates Authorization Response based on the request

Returns:



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/simple_oauth2/generators/authorization.rb', line 12

def generate_for(env, &_block)
  authorization = Rack::OAuth2::Server::Authorize.new do |request, response|
    request.unsupported_response_type! unless allowed_types.include?(request.response_type.to_s)

    if block_given?
      yield request, response
    else
      execute_default(request, response)
    end
  end

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