Skip to main content

Doorkeeper Api Integration in Rails

for controller:::
doorkeeper_for :all
require 'rest-client'
require 'json'

def index
client_id = 'my_client_id...'
client_secret = 'my_client_secret...'

response = RestClient.post 'http://localhost:3000/oauth/token', {
  grant_type: 'client_credentials',
  client_id: client_id,
  client_secret: client_secret
}
token = JSON.parse(response)["access_token"]
getiing data to apis for doorkeeper-----------------
####Getting data from doorkeeper api##########
response = RestClient.get('http://localhost:3000/api/v1/profiles.json', { 'Authorization' => "Bearer #{token}"})
data = JSON.parse(response)
p data.inspect
####Posting data to api##########
response_user = RestClient.post('http://localhost:3000/api/v1/profiles.json',{
      profile:
      {
      first_name: params[:first_name]
      last_name: params[:last_name]
      }},
     { 'Authorization' => "Bearer #{token}"})

    user_data = JSON.parse(response_user)
    p user_data.inspect
end

Comments