我已经实现了一个自定义的 OmniAuth 策略,以及一个继承自 Discourse 的 Auth::ManagedAuthenticator 的认证器。
然而,在开发环境中测试时,我最终会跳转到这个页面,而不是直接登录:
虽然信息已通过 auth hash 正确填充,但我不希望用户在此处修改他们的用户名或姓名。我该如何修改我的实现或论坛设置,以跳过此页面,并直接创建(如果不存在)用户账户并登录?
认证器:
class MyAuthenticator < ::Auth::ManagedAuthenticator
def name
'my_authenticator'
end
def enabled?
true
end
def register_middleware(omniauth)
omniauth.provider name.to_sym, {}
end
end
策略:
require 'omniauth'
...
class OmniAuth::Strategies::MyAuthenticator
include OmniAuth::Strategy
option :name, "my_authenticator"
...
def callback_phase
...
@user_id = ...
@username = ...
@avatar = ...
@email = ...
...
end
...
def auth_hash
{
provider: "my_authenticator",
uid: @user_id,
info: {
name: @username,
image: @avatar,
email: @email
},
extra: {}
}
end
end
OmniAuth.config.add_camelization('my_authenticator', 'MyAuthenticator')
plugin.rb:
before_auth do
...
auth_provider authenticator: MyAuthenticator.new()
...
end
