我试图在rails中实现与谷歌或任何其他社交网络的登录。我已经按照Codeplace教程http://r12---sn-cvh7kn7y.googlevideo.com/videoplayback?sparams=dur,ei,expire,id,i
我遇到了以下问题
Error: invalid_request
Missing required parameter: client_id
Learn more
Request Details
access_type=offline
scope=email profile
response_type=code
redirect_uri=http://localhost:9292/auth/google_oauth2/callback
state=2f6a1b1d2e0a2fb1c75647a6d145efa907c3ee9038a8bb54
client_id=
我的相关代码是-omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
provider :google_oauth2,ENV['238730796202-.com'],ENV['TyqJqfiOJLoLgqRRGgTIynxt']
provider :facebook, ENV['1585034338471672'],ENV['3211b382a1636bdc747d37921aab2a90']
end
sessioncontroller.rb
class SessionsController < ApplicationController
def create
auth = request.env["omniauth.auth"]
puts auth
session[:omniauth] = auth.except('extra')
user = User.sign_in_from_omniouth(auth)
session[:user_id] = user_id
redirect_to root_url, notice:"Sign In"
end
def destroy
session[:user_id] = nil
session[:omniauth] = nil
redirect_to root_url, notice:"Sign OUT"
end
end
用户。rb
class User < ActiveRecord::Base
def self.sign_in_from_omniouth(auth)
find_by(provider: auth['provider'], uid: auth['uid'])||
create_user_from_omniauth(auth)
end
def self.create_user_from_omniauth(auth)
create(
provider:auth['provider'],
uid:auth['uid'],
name:auth['info']['name']
)
end
end
end
有谁能帮我吗? 由于遇到错误,client_id
缺失。
尝试文档中给出的基本步骤,其中通过执行以下操作从Google API控制台获取OAuth 2.0凭据:
访问Google API控制台获取OAuth 2.0凭据,例如Google和您的应用程序都知道的
client ID
和client secret
。
请尝试通过Google API控制台启用"Contacts API"和"Google+ API"。正如在这篇GitHub文章中所指出的,如果这些未启用,您将收到OAuth2::Error(Error: "Invalid credentials")
,说明当您尝试进行身份验证时未配置访问。
请尝试通过给定的GitHub帖子,OmniAuth Google OAuth2策略的重要细节。