Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client information headers #31

Merged
merged 5 commits into from
May 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/auth0/mixins/initializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def initialize(config)
domain = api_domain options
raise InvalidApiNamespace, "Api namespace must supply an API domain" if domain.nil?
self.class.base_uri "https://#{domain}"
self.class.headers "Content-Type" => 'application/json'

self.class.headers client_headers

self.extend Auth0::Api::AuthenticationEndpoints
@client_id = options[:client_id]
initialize_v2(options) if api_v2?(options)
Expand All @@ -28,6 +30,14 @@ def self.included(klass)

private

def client_headers
{
'Content-Type' => 'application/json',
'User-Agent' => "Ruby/#{RUBY_VERSION}",
'Auth0-Client' => "Ruby/#{Auth0::VERSION}"
}
end

def api_domain(options)
options[:domain] || options[:namespace]
end
Expand Down
24 changes: 24 additions & 0 deletions spec/integration/lib/auth0/auth0_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,28 @@
let(:credentials) { v2_credentials.merge({access_token: ENV["MASTER_JWT"]}) }
end

context "client headers" do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it will better to test this in an unit tests but we can have this here till we re-do them

let(:client) { Auth0::Client.new(v2_credentials.merge({access_token: 'abc123', domain: 'myhost.auth0.com'})) }
let(:headers) { client.class.headers }

it "has the correct headers present" do
expect(headers.keys.sort).to eql ['Auth0-Client', 'Authorization', 'Content-Type', 'User-Agent']
end

it "uses the correct access token" do
expect(headers['Authorization']).to eql "Bearer abc123"
end

it "is always json" do
expect(headers['Content-Type']).to eql 'application/json'
end

it "sets the ruby version" do
expect(headers['User-Agent']).to eql "Ruby/#{RUBY_VERSION}"
end

it "sets the client version" do
expect(headers['Auth0-Client']).to eql "Ruby/#{Auth0::VERSION}"
end
end
end