fixed 第三方授权登录配置

This commit is contained in:
xxq250 2022-12-05 17:46:21 +08:00
parent 6b846b10bb
commit daf7514afe
2 changed files with 8 additions and 5 deletions

View File

@ -2,6 +2,7 @@ class Oauth::CallbacksController < Oauth::BaseController
def create def create
process_callback process_callback
rescue Exception => e rescue Exception => e
Rails.logger.info "授权失败:#{e}"
tip_exception("授权失败") tip_exception("授权失败")
end end
@ -38,7 +39,9 @@ class Oauth::CallbacksController < Oauth::BaseController
new_user = true new_user = true
login = build_login_name(platform, auth_hash.info.nickname) login = build_login_name(platform, auth_hash.info.nickname)
mail = "#{login}@example.org" if mail.blank? mail = "#{login}@example.org" if mail.blank?
reg_result = autologin_register(login, mail, "Ec#{login}2022#", platform, nil, nickname) code = %W(0 1 2 3 4 5 6 7 8 9)
rand_password = code.sample(10).join
reg_result = autologin_register(login, mail, rand_password, platform, nil, nickname)
Rails.logger.info("[OAuth2] omniauth.auth [reg_result] #{reg_result} ") Rails.logger.info("[OAuth2] omniauth.auth [reg_result] #{reg_result} ")
if reg_result[:message].blank? if reg_result[:message].blank?
open_user = "OpenUsers::#{platform.to_s.capitalize}".constantize.create!(user_id: reg_result[:user][:id], uid: uid, extra: auth_hash.extra) open_user = "OpenUsers::#{platform.to_s.capitalize}".constantize.create!(user_id: reg_result[:user][:id], uid: uid, extra: auth_hash.extra)

View File

@ -1,9 +1,9 @@
config = Rails.application.config_for(:configuration) config = Rails.application.config_for(:configuration)
OmniAuth.config.add_camelization 'qq', 'QQ' if config.dig("oauth", "qq") OmniAuth.config.add_camelization 'qq', 'QQ' if config.dig("oauth", "qq")
OmniAuth.config.add_camelization 'github', 'GitHub' if config.dig("oauth", "github") # OmniAuth.config.add_camelization 'github', 'GitHub' if config.dig("oauth", "github")
OmniAuth.config.add_camelization 'gitee', 'Gitee' if config.dig("oauth", "gitee") # OmniAuth.config.add_camelization 'gitee', 'Gitee' if config.dig("oauth", "gitee")
OmniAuth.config.add_camelization 'wechat', 'Wechat' if config.dig("oauth", "wechat") # OmniAuth.config.add_camelization 'wechat', 'Wechat' if config.dig("oauth", "wechat")
OmniAuth.config.logger = Rails.logger OmniAuth.config.logger = Rails.logger
OmniAuth.config.before_request_phase = nil OmniAuth.config.before_request_phase = nil
OmniAuth.config.before_callback_phase = nil OmniAuth.config.before_callback_phase = nil
@ -22,6 +22,6 @@ Rails.application.config.middleware.use OmniAuth::Builder do
provider :gitee, config.dig("oauth", "gitee", "appid"), config.dig("oauth", "gitee", "secret"), { provider_ignores_state: true, scope: "user_info emails" } provider :gitee, config.dig("oauth", "gitee", "appid"), config.dig("oauth", "gitee", "secret"), { provider_ignores_state: true, scope: "user_info emails" }
end end
if config.dig("oauth", "wechat").present? if config.dig("oauth", "wechat").present?
provider :gitee, config.dig("oauth", "wechat", "appid"), config.dig("oauth", "wechat", "secret"), { provider_ignores_state: true, scope: "snsapi_login" } provider :wechat, config.dig("oauth", "wechat", "appid"), config.dig("oauth", "wechat", "secret"), { provider_ignores_state: true, scope: "snsapi_login" }
end end
end end