Yandex OAuth strategy for OmniAuth
This gem contains the unofficial Yandex OAuth2 strategy for OmniAuth.
Getting Started
Prerequisites
This gem require OmniAuth
But you no need add gem 'omniauth'
.
This gem already added.
Installation
gem "omniauth-yandex"
Register new app for sync on yandex:
- Obtain API key for your app at Yandex OAuth app registration page
- Enter callback url for auth
- Select service and its data for auth
Usage
-
Add to omniauth.rb yandex provider:
Rails.application.config.middleware.use OmniAuth::Builder do provider :yandex, ENV['YANDEX_ID'], ENV['YANDEX_PASSWORD'] end
-
Add route
get '/auth/:provider/callback', to: 'sessions#create'
-
Create SessionController
note: This controller only as example how to create user by callback
class SessionsController < ApplicationController
def create
@user = User.find_or_create_from_auth_hash(auth_hash)
redirect_to '/'
end
protected
def auth_hash
request.env['omniauth.auth']
end
end
-
Run rails server and open page
localhost:3000/auth/yandex
-
Sign In yandex by own username and password
-
Take app permissions:
Contributing
Please read Code of Conduct and Contributing Guidelines for submitting pull requests to us.
Versioning
We use SemVer for versioning. For the versions available, see the tags on this repository.
Changelog
The changelog is here.
Authors
- Kir Shatrov - Initial work
- Dmitry Koropenko - Maintainer
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License.