Class: Leash::Provider::TokenController

Inherits:
Leash::ProviderController show all
Defined in:
app/controllers/leash/provider/token_controller.rb

Constant Summary collapse

GRANT_TYPES =
[ "authorization_code" ].freeze

Constants inherited from Leash::ProviderController

Leash::ProviderController::CLIENT_ID_REGEXP

Instance Method Summary collapse

Instance Method Details

#tokenObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/leash/provider/token_controller.rb', line 7

def token
  case @grant_type
  when "authorization_code"
    params.require("code")

    if Leash::Provider::AuthCode.valid?(params[:code])
      access_token = Leash::Provider::AccessToken.assign_from_auth_code! Leash::Provider::AuthCode.find_by_auth_code(params[:code])

      render json: { access_token: access_token, token_type: "bearer" }
    end

  else
    fail "Should not be reached"
  end
end