Sha256: e95611da792db80b3dac1c8d9cbcd4ddbdad60fb8074b1a04a745b71c087ee3d

Contents?: true

Size: 1.8 KB

Versions: 38

Compression:

Stored size: 1.8 KB

Contents

require 'spec_helper_integration'

describe 'Client Credentials Request' do
  let(:client) { FactoryGirl.create :application }

  context 'a valid request' do
    it 'authorizes the client and returns the token response' do
      headers = authorization client.uid, client.secret
      params  = { grant_type: 'client_credentials' }

      post '/oauth/token', params, headers

      should_have_json 'access_token', Doorkeeper::AccessToken.first.token
      should_have_json_within 'expires_in', Doorkeeper.configuration.access_token_expires_in, 1
      should_not_have_json 'scope'
      should_not_have_json 'refresh_token'

      should_not_have_json 'error'
      should_not_have_json 'error_description'
    end

    context 'with scopes' do
      before do
        optional_scopes_exist :write
      end

      it 'adds the scope to the token an returns in the response' do
        headers = authorization client.uid, client.secret
        params  = { grant_type: 'client_credentials', scope: 'write' }

        post '/oauth/token', params, headers

        should_have_json 'access_token', Doorkeeper::AccessToken.first.token
        should_have_json 'scope', 'write'
      end
    end
  end

  context 'an invalid request' do
    it 'does not authorize the client and returns the error' do
      headers = {}
      params  = { grant_type: 'client_credentials' }

      post '/oauth/token', params, headers

      should_have_json 'error', 'invalid_client'
      should_have_json 'error_description', translated_error_message(:invalid_client)
      should_not_have_json 'access_token'

      expect(response.status).to eq(401)
    end
  end

  def authorization(username, password)
    credentials = ActionController::HttpAuthentication::Basic.encode_credentials username, password
    { 'HTTP_AUTHORIZATION' => credentials }
  end
end

Version data entries

38 entries across 38 versions & 2 rubygems

Version Path
doorkeeper-sequel-1.3.1 spec/requests/flows/client_credentials_spec.rb
doorkeeper-sequel-1.3.0 spec/requests/flows/client_credentials_spec.rb
doorkeeper-sequel-1.2.3 spec/requests/flows/client_credentials_spec.rb
doorkeeper-sequel-1.2.2 spec/requests/flows/client_credentials_spec.rb
doorkeeper-4.2.6 spec/requests/flows/client_credentials_spec.rb
doorkeeper-4.2.5 spec/requests/flows/client_credentials_spec.rb
doorkeeper-sequel-1.2.1 spec/requests/flows/client_credentials_spec.rb
doorkeeper-4.2.0 spec/requests/flows/client_credentials_spec.rb
doorkeeper-4.1.0 spec/requests/flows/client_credentials_spec.rb
doorkeeper-4.0.0 spec/requests/flows/client_credentials_spec.rb
doorkeeper-4.0.0.rc4 spec/requests/flows/client_credentials_spec.rb
doorkeeper-4.0.0.rc3 spec/requests/flows/client_credentials_spec.rb
doorkeeper-4.0.0.rc2 spec/requests/flows/client_credentials_spec.rb
doorkeeper-4.0.0.rc1 spec/requests/flows/client_credentials_spec.rb
doorkeeper-3.1.0 spec/requests/flows/client_credentials_spec.rb
doorkeeper-3.0.1 spec/requests/flows/client_credentials_spec.rb
doorkeeper-2.2.2 spec/requests/flows/client_credentials_spec.rb
doorkeeper-3.0.0 spec/requests/flows/client_credentials_spec.rb
doorkeeper-3.0.0.rc2 spec/requests/flows/client_credentials_spec.rb
doorkeeper-3.0.0.rc1 spec/requests/flows/client_credentials_spec.rb