Login or Sign up for an account on Naver.
Visit here to register an application to use Naver API.
- Enter details of company.
- Select Neo Aro (Login with Naver ID) as Usage API
- Select PC Web as Open API Service Environment.
- Set Service URL e.g. https://ngrok.io/
- Set Callback URL e.g. https://9420712f.ngrok.io/path/to/naver/callback
- Click Register.
Note down the CLIENT_ID and CLIENT_SECRET under Summary on application dashboard.
Add following to Gemfile:
gem 'omniauth-naver', '~> 0.1.0'
Run bundle install
.
# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :naver, CLIENT_ID, CLIENT_SECRET,
{ callback_path: '/path/to/callback/action' }
end
!/ app/views/sessions/login.html.slim
= link_to 'Login via Naver', '/auth/naver'
# app/controllers/sessions_controller.rb
def naver_callback
omniauth = request.env['omniauth.auth'] # => #<OmniAuth::AuthHash credentials=#<OmniAuth::AuthHash expires=true expires_at=1497596041 refresh_token="jC40Md" token="AAAAQU"> extra=#<OmniAuth::AuthHash raw_info=#<OmniAuth::AuthHash data=#<OmniAuth::AuthHash response=#<OmniAuth::AuthHash age="20-29" birthday="01-20" email="[email protected]" enc_id="200184" gender="M" id="144207" name="Jagdeep Singh" nickname="Jagdeep Singh" profile_image="https://ssl.pstatic.net/path/to/image.png"> result=#<OmniAuth::AuthHash message="success" resultcode="00">>>> info=#<OmniAuth::AuthHash::InfoHash email="[email protected]" gender="male" image="https://ssl.pstatic.net/path/to/image.png" name="Jagdeep Singh"> provider="naver" uid="200184">
end