Class: Simple::OAuth2::Generators::Token

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

Overview

Token generator class Processes the request by required Grant Type and builds the response

Class Method Summary collapse

Methods inherited from Base

allowed_grants, config

Class Method Details

.generate_for(env, &_block) ⇒ Object


8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/simple_oauth2/generators/token.rb', line 8

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

  Simple::OAuth2::Responses.new(token.call(env))
end