Rails 앱에서 Google 인증을 구현하려고하는데 문제가 있습니다.Google 인증 오류 Ruby on Rails
https://richonrails.com/articles/google-authentication-in-ruby-on-rails/에 따라, 나는 구글의 개발자 콘솔 'omniauth.rb'
OmniAuth.config.logger = Rails.logger
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2, '*****', '*****', {client_options: {ssl: {ca_file: Rails.root.join("cacert.pem").to_s}}}
end
에서받은 키를 내 이니셜을 만든 내가
조치를 만들 '어떤 경로를# GOOGLE AUTH
get 'auth/:provider/callback', to: 'sessions#create'
get 'auth/failure', to: redirect('/')
get 'signout', to: 'sessions#destroy', as: 'signout'
내 세션
추가def create
user = User.from_omniauth(env["omniauth.auth"])
sign_in user
flash[:success] = 'Logged in!'
redirect_to root_path
end
그리고 사용자의 User.from_omniauth
방법 모델 나는 또한 bcrypt 인증을 사용하고 있기 때문에
def self.from_omniauth(auth)
where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |user|
user.password = user.password_confirmation = user.password_digest = SecureRandom.urlsafe_base64(n=6)
user.provider = auth.provider
user.uid = auth.uid
user.name = auth.info.name
user.oauth_token = auth.credentials.token
user.oauth_expires_at = Time.at(auth.credentials.expires_at)
user.save!
end
end
나는 임의의 암호를 설정하고 모든 사용자가 하나의 암호를 가지고 강제
마지막으로, 내보기에 내가 가진 로그인을위한 버튼
= link_to "Sign in with Google", "/auth/google_oauth2", id: "sign_in", class: "btn btn-primary"
문제는 내가 그것을 클릭하면 '오류가 세션에 보여주고, 일을 만들지 않는다는 것입니다 user = User.from_omniauth(env["omniauth.auth"])
:
NameError at /auth/google_oauth2/callback
undefined local variable or method `env' for #<SessionsController:0x956eb90>
다른 번에 SSL_connect SYSCALL returned=5 errno=0 state=SSLv2/v3 read server hello A (OpenSSL::SSL::SSLError)
을 던지면 다른 실수가 될 것입니다.
대신 'ENV'를 사용해 보셨습니까? – SRack