class Doorkeeper::OAuth::Authorization::Token

def build_context(pre_auth_or_oauth_client, grant_type, scopes, resource_owner)

def build_context(pre_auth_or_oauth_client, grant_type, scopes, resource_owner)
  oauth_client = if pre_auth_or_oauth_client.respond_to?(:application)
                   pre_auth_or_oauth_client.application
                 elsif pre_auth_or_oauth_client.respond_to?(:client)
                   pre_auth_or_oauth_client.client
                 else
                   pre_auth_or_oauth_client
                 end
  Doorkeeper::OAuth::Authorization::Context.new(
    client: oauth_client,
    grant_type: grant_type,
    scopes: scopes,
    resource_owner: resource_owner,
  )
end