gpt4 book ai didi

ruby-on-rails - 无法从 GoogleOauth2 对您进行身份验证,因为 "Authenticity error"

转载 作者:行者123 更新时间:2023-12-04 00:13:32 33 4
gpt4 key购买 nike

嗨,我在 GoogleOauth2 API 中遇到此错误
“无法从 GoogleOauth2 对您进行身份验证,因为真实性错误”和“未找到,身份验证通过”并且无法找出问题所在。
这是我的 OmniauthCallbacksController
'''

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
def google_oauth2
@user = User.from_omniauth(request.env["omniauth.auth"])
if @user.persisted?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
# auth = request.env["omniauth.auth"]
# @user.access_token = auth.credentials.token
# @user.expires_at = auth.credentials.expires_at
# @user.refresh_token = auth.credentials.refresh_token
# @user.save!
sign_in @user, event: :authentication
redirect_to tasks_path
else
session["devise.google_data"] = request.env["omniauth.auth"]
# redirect_to new_user_registration_url
end
end
end
'''
我的路线
Rails.application.routes.draw do
devise_for :users, controllers: { omniauth_callbacks: "users/omniauth_callbacks" }
resources :users
end
设计文件
Devise.setup do |config|
config.mailer_sender = 'DokRx@dispostable.com'

require 'devise/orm/active_record'

config.case_insensitive_keys = [:email]

config.strip_whitespace_keys = [:email]

config.skip_session_storage = [:http_auth]

config.stretches = Rails.env.test? ? 1 : 12

config.reconfirmable = true

config.expire_all_remember_me_on_sign_out = true

config.password_length = 6..128
config.email_regexp = /\A[^@\s]+@[^@\s]+\z/

config.reset_password_within = 6.hours

config.sign_out_via = :delete

google_client_id = Rails.application.credentials.google_oauth2[:google_client_id]
google_client_secret = Rails.application.credentials.google_oauth2[:google_client_secret]
config.omniauth :google_oauth2, google_client_id, google_client_secret,
scope: 'userinfo.email, calendar',
skip_jwt: true,
access_type: "offline",
prompt: "consent",
select_account: true



end

最佳答案

1.) 检查您是否拥有此版本的设备以修复“未找到,身份验证通路”问题:

gem 'devise', github: 'heartcombo/devise', branch: 'ca-omniauth-2'
并确保您提出邮寄请求。举个例子 :
= link_to "Sign in with Facebook", user_facebook_omniauth_authorize_path, method: :post
https://github.com/heartcombo/devise/issues/5236
2.) 安装以下 gem 以修复真实性错误:
gem "omniauth-rails_csrf_protection"
https://github.com/cookpad/omniauth-rails_csrf_protection

关于ruby-on-rails - 无法从 GoogleOauth2 对您进行身份验证,因为 "Authenticity error",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66086606/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com