Skip to content

Enable Basic authorization for access tokens

Mohamed Ziata edited this page Sep 21, 2017 · 2 revisions

version >=1.1.1

To enable Basic authorization for access tokens, we will need to configure doorkeeper's access_token_methods in our doorkeeper initializer.

Note: This is the list of methods that will be used, be sure to include any other methods that your application will require.
# config/initializers/doorkeeper.rb
Doorkeeper.configure do
    access_token_methods :from_bearer_authorization, :from_basic_authorization, :from_access_token_param
end

This will allow a user to interact with your API via Basic authentication like so:

token=ec4826413c3b9649d8f6b883972a0f632576d879e3f65ae1fd5448d6e0bf327d
curl -u "$token:" http://localhost:3000/api/v1/profiles.json
curl "http://$token:@localhost:3000/api/v1/profiles.json"

Or in ruby:

RestClient.get 'http://localhost:3000/api/v1/profiles.json', { 'Authorization' => "Basic #{Base64.encode64("#{token}:")}" }
# => "[{"email":"[email protected]","id":25,"name":"Jorge Ward","username":"leonor"}, ...]"
Clone this wiki locally