Class: Grape::OAuth2::Generators::Token

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

Overview

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

Constant Summary collapse

STRATEGY_CLASSES =

Grant type => OAuth2 strategy class

{
  password: Grape::OAuth2::Strategies::Password,
  client_credentials: Grape::OAuth2::Strategies::ClientCredentials,
  refresh_token: Grape::OAuth2::Strategies::RefreshToken
}.freeze

Class Method Summary collapse

Methods inherited from Base

allowed_grants, config

Class Method Details

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

Generates Token Response based on the request.

Returns:



19
20
21
22
23
24
25
26
27
28
29
30
31
# 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