In this blog, we will implement authentication with pinterest and posting on pinterset board.
We can divide it i two parts. In first part we will do pinterest authentication and in second part we will do posting on pinterest -
1.) We can do pinterest authentication with gem 'omniauth-pinterest'
So, in Gemfile -
gem 'omniauth-pinterest'
After that in config/intializer/omniauth.b -
Rails.application.config.middleware.use OmniAuth::Builder do
# get appid and app_seceret from creating a developer account in pinterest
provider :pinterest, ['app_id'], ['app_secret'], {:display => "popup"}
end
In routes.rb -
get '/auth/pinterest', as: 'pinterest-authentication'
# Here we are using oauths controller. Set callback url in pinterest developer account as https://localhost:3000/auth/pinterest/callback
get '/auth/pinterest/callback' => 'oauths#pinterest_callback', as: 'pinterest-callback'
Now in controller -
def pinterest_callback
token = request.env['omniauth.auth']['credentials']['token']
pinterest_id = request.env['omniauth.auth'].uid
end
Above method return token and pinterest id of pinterset user.
Now, we have all done with pinterest authentication.
In second part of the blog we will do pinterest posting.
To be continued ......