ueberauth_identity有一个登录和注册的单一回调示例,但这会导致错误处理。有没有办法进行单独的注册回调?
问问题
238 次
1 回答
0
我想说这只是发送特定参数并通过所有相关调用传播它的问题。我不确定它最终会“清洁多少”。
例如,假设您的设置与文档中的完全一样:
scope "/auth", MyApp do
pipe_through :browser
get "/:provider", AuthController, :request
get "/:provider/callback", AuthController, :callback
post "/identity/callback", AuthController, :identity_callback
end
因此,当您想强制用户登录时,您会将他重定向到以下路线:
Routes.auth_path(@conn, :request, "identity")
它的实现有点像这样:
defmodule UeberauthExampleWeb.AuthController do
use UeberauthExampleWeb, :controller
plug Ueberauth
alias Ueberauth.Strategy.Helpers
def request(conn, _params) do
render(conn, "request.html", callback_url: Helpers.callback_url(conn))
end
# ...
end
现在,没有什么能真正阻止您添加一些查询参数,使其看起来像这样:
Routes.auth_path(@conn, :request, "identity", login: true)
您可以将其传播到回调 URL:
def request(conn, %{"login" => _}) do
callback_url = Helpers.callback_url(conn) <> "?login=true"
render(conn, "request.html", callback_url: callback_url)
end
这样您就可以最终在回调中进行模式匹配:
def identity_callback(%{assigns: %{ueberauth_auth: auth}} = conn, %{"login" => _}) do
# ...
end
于 2021-05-20T15:36:41.670 回答