我一直在努力让我的rails应用程序使用谷歌登录和日历无济于事。我可以获得谷歌登录页面,但在我输入密码后,我在使用日历时遇到运行时错误。当我尝试谷歌身份验证路径时,我得到一个不同的错误。我仍然可以获得谷歌登录屏幕,但我得到了一个客户端密码丢失错误'即使我已将其输入application.yml和device.rb中。不知道要添加什么信息因为我是新手。 我的错误:
开始发布" / users / sign_in" for 107.0.0.1 at 2017-10-22 12:10:07 -0700由Devise处理:: SessionsController #create as HTML参数:{" utf8" =>"✓" ," authenticity_token" =>" hw + HZafhIkLohmPvpVdtegQtctmLDX9vCFa2HHoYJTMcFQi7yhaq3Cq / 1 + NJpTAEbY + Un9GIVc8AoGZxiE2A2g ==","用户" => {"电子邮件&# 34; =>" Hodari@giddengeniusproject.org","密码" =>" [过滤]"," remember_me" = >" 0"},"提交" =>"登录"}在28ms内完成500内部服务器错误(ActiveRecord:0.0ms)
RuntimeError(无效策略some_external_strategy):warden(1.2.7)lib / warden / proxy.rb:371:在_ _fetch_strategy' warden (1.2.7) lib/warden/proxy.rb:355:in
块_run_strategies_for' warden(1.2.7)lib / warden / proxy.rb:354:在each' warden (1.2.7) lib/warden/proxy.rb:354:in
_ run_strategies_for' warden(1.2.7)lib / warden / proxy.rb:324:in _perform_authentication' warden (1.2.7) lib/warden/proxy.rb:128:in
authenticate!'设计(4.2.1)app / controllers / devise / sessions_controller.rb:17:在'create' ac
"
Rails.application.config.middleware.use Warden::Manager do |manager|
manager.default_strategies [:omniauth, :params]
end
Warden::Manager.serialize_into_session do |user|
user.persistence_token
end
Warden::Manager.serialize_from_session do |id|
User.where(persistence_token: id).first
end
#
module UserCredentialAuthentication
def verify_against_old_credentials( user, password )
Sha512.matches?( user.sha512_password, password, user.sha512_salt )
end
def transition_from_sha512!( user, password )
user.password = password
user.sha512_password = nil
user.sha512_salt = nil
user.save
end
def authenticate!
Rails.logger.warn("[AUTH] Authenticating user #{username} from #{medium}")
user = User.find_by_username_or_email(username)
if user.blank?
Rails.logger.warn("[AUTH] No Such User")
fail "Invalid email or password"
elsif user.sha512_password.not.blank? && verify_against_old_credentials( user, password )
Rails.logger.warn("[AUTH] User #{user.email} authenticated with a SHA512 password.")
transition_from_sha512!( user, password )
success! user
elsif user.password_digest && user.authenticate( password )
Rails.logger.warn("[AUTH] User #{user.email} authenticated with a password.")
success! user
else
Rails.logger.warn("[AUTH] Bad Password")
fail "Invalid email or password"
end
end
end
Warden::Strategies.add(:omniauth) do
include UserCredentialAuthentication
def medium
'omniauth'
end
def valid?
Rails.logger.warn("[OMNIAUTH] checking omniauth")
auth.provided? && auth.basic?
end
def username
auth.credentials[0]
end
def password
auth.credentials[1]
end
def auth
@omniauth ||= Rack::Auth::Basic::Request.new(env)
end
end
Warden::Strategies.add(:params) do
include UserCredentialAuthentication
def medium
'params'
end
def valid?
Rails.logger.warn("[OMNIAUTH] checking params")
credential_params['username'] && credential_params['password']
end
def username
credential_params['username']
end
def password
credential_params['password']
end
def credential_params
p = params.blank? ? post_params : params
p['user_session'] || {}
end
def post_params
@post_params ||= get_post_params
end
def get_post_params
if( request.post? )
begin
body = request.body.read
request.body.rewind
JSON.parse( body )
end
else
{}
end
end
end
> "
>
#class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController # You should configure your model like this: #devise :omniauthable, omniauth_providers: [:google] # You should also create an action method in this controller like this: # def twitter # end def google_oauth2 # You need to implement the method below in your model (e.g. app/models/user.rb) @user = User.from_omniauth(request.env['omniauth.auth']) sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated set_flash_message(:notice, :success, :kind => "Google Oauth2") if is_navigational_format? if @user.persisted? flash[:notice] = I18n.t 'devise.omniauth_callbacks.success', kind: 'Google' sign_in_and_redirect @user, event: :authentication else session['devise.google_data'] = request.env['omniauth.auth'].except(:extra) # Removing extra as it can
溢出一些会话商店 redirect_to new_user_registration_url,alert:@ user.errors.full_messages.join(&#34; \ n&#34;) 结束 端
# GET|POST /resource/auth/google # def passthru # super # render status: 404, plain: "Not found. Authentication passthru." # end # # GET|POST /users/auth/google/callback # def failure # super # end # # protected # # #The path used when OmniAuth fails def after_omniauth_failure_path_for(google_oauth2) redirect_to root_path super(:user) end end end
会话控制器
类Users :: SessionsController&lt;设计:: SessionsController# before_action:configure_sign_in_params,only:[:create] #include 可访问#skip_before_action:check_user,仅:: destroy
#GET / resource / sign_in#def new #super #end POST / resource / sign_in def create user = User.from_omniauth(env [&#34; omniauth.auth&#34;]) session [:user_id] = user.id redirect_to root_path 超级终端
DELETE / resource / sign_out def destroy session [:user_id] = nil redirect_to root_path 超级终端