Answer the question
In order to leave comments, you need to log in
Yandex OAuth login not working?
Rails 4.2.5+Devise 3.5.1
Gemfile: https://rubygems.org/gems/omniauth-yandex/versions... config/secrets.yml:gem 'omniauth-yandex'
development:
yandex_auth_app_id: xxxx
yandex_auth_secret: yyyy
config.omniauth :twitter,
Rails.application.secrets.twitter_app_id,
Rails.application.secrets.twitter_app_secret
config.omniauth :facebook,
Rails.application.secrets.facebook_app_id,
Rails.application.secrets.facebook_app_secret
config.omniauth :vkontakte,
Rails.application.secrets.vkontakte_app_id,
Rails.application.secrets.vkontakte_app_secret
config.omniauth :yandex,
Rails.application.secrets.yandex_auth_app_id,
Rails.application.secrets.yandex_auth_secret
class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
include SearchLoadFromSession
def vkontakte
provider_login 'ВКонтакте'
end
def twitter
provider_login 'Twitter'
end
def facebook
provider_login 'Facebook'
end
def yandex
provider_login 'Яндекс'
end
private
def provider_login kind
auth = request.env['omniauth.auth']
@user = User.from_omniauth auth
if @user.persisted?
sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated
set_flash_message(:notice, :success, :kind => kind) if is_navigational_format?
else
flash[:error] = 'Ошибка авторизации.'
redirect_to root_path
end
end
end
Rails.application.routes.draw do
devise_for :users, :controllers => { :omniauth_callbacks => 'users/omniauth_callbacks',
:registrations => 'users/registrations',
:confirmations => 'users/confirmations',
:sessions=> 'users/sessions' },
:path => '',
:path_names => { :sign_in => 'вход', :sign_out => 'выход', :sign_up => 'регистрация'}
...
end
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :trackable, :validatable, :confirmable,
:omniauthable,
:omniauth_providers => [:twitter, :facebook, :vkontakte, :yandex]
.......
Yandex.OAuth redirects the user to the address specified in the Callback URL field when registering the application. The confirmation code (or description of the error) is passed in the redirect URL parameter.
The application receives the redirect address and retrieves the verification code.
The application sends a POST request with a code.
Yandex.OAuth returns a token in the response body.
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question