Skip to content

Commit

Permalink
Merge a66534f into 7691a2c
Browse files Browse the repository at this point in the history
  • Loading branch information
nikz committed Jun 20, 2016
2 parents 7691a2c + a66534f commit ff4d612
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/oauth2/strategy/client_credentials.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ def authorize_url
def get_token(params = {}, opts = {})
request_body = opts.delete('auth_scheme') == 'request_body'
params['grant_type'] = 'client_credentials'
params.merge!(request_body ? client_params : {:headers => {'Authorization' => authorization(client_params['client_id'], client_params['client_secret'])}})
if request_body
params.merge!(client_params)
else
authorization_header = {'Authorization' => authorization(client_params['client_id'], client_params['client_secret'])}
params[:headers] = (params[:headers] || {}).merge(authorization_header)
end
@client.get_token(params, opts.merge('refresh_token' => nil))
end

Expand Down
12 changes: 12 additions & 0 deletions spec/oauth2/strategy/client_credentials_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
stub.post('/oauth/token', 'grant_type' => 'client_credentials') do |env|
client_id, client_secret = Base64.decode64(env[:request_headers]['Authorization'].split(' ', 2)[1]).split(':', 2)
client_id == 'abc' && client_secret == 'def' || raise(Faraday::Adapter::Test::Stubs::NotFound)
@last_headers = env[:request_headers]
case @mode
when 'formencoded'
[200, {'Content-Type' => 'application/x-www-form-urlencoded'}, kvform_token]
Expand Down Expand Up @@ -78,4 +79,15 @@
end
end
end

describe '#get_token (with extra header parameters)' do
before do
@mode = 'json'
@access = subject.get_token(:headers => {'X-Extra-Header' => 'wow'})
end

it 'sends the header correctly.' do
expect(@last_headers['X-Extra-Header']).to eq('wow')
end
end
end

0 comments on commit ff4d612

Please sign in to comment.