Class: Doorkeeper::TokensController

Inherits:
Object
  • Object
show all
Defined in:
lib/tokens_controller.rb

Overview

TODO Is there a better way to implement this? This monkey patch is required to ensure the OAuth2 token includes which team was connected to. It gets required by BulletTrain::Api.set_configuration.

Instance Method Summary collapse

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/tokens_controller.rb', line 6

def create
  headers.merge!(authorize_response.headers)

  user = if authorize_response.is_a?(Doorkeeper::OAuth::ErrorResponse)
    nil
  else
    User.find(authorize_response.token.resource_owner_id)
  end

  # Add the selected `team_id` to this response.
  render json: authorize_response.body.merge(user&.teams&.one? ? {"team_id" => user.team_ids.first} : {}),
    status: authorize_response.status
rescue Doorkeeper::Errors::DoorkeeperError => e
  handle_token_exception(e)
end