我使用的是 Phoenix 1.3 版和 UeberAuth "~> 0.6"。我目前收到一个我认为不应该发生的 CRSF 错误,但我很可能犯了错误。
在我的 router.ex 文件中,我有以下内容:
scope "/auth", DiscussWeb do
pipe_through :browser
get "/:provider", AuthController, :request
get "/:provider/callback", AuthController, :callback
end
在我的控制器文件中,回调如下:
def callback(conn, params) do
callback_t(conn, params)
conn
|> put_flash(:info, "Github Authenticate?")
|> redirect(to: Routes.topic_path(conn, :index))
end
defp callback_t(conn, params) do
IO.puts "+++"
IO.inspect(conn.assigns)
IO.puts "+++"
IO.inspect(params)
IO.puts "+++"
end
在浏览器中,我确实被重定向到 GitHub 进行登录。但是,我收到以下回复:
debug] Processing with DiscussWeb.AuthController.callback/2
Parameters: %{"code" => "908a69a812c17af0ab0b", "provider" => "github"}
Pipelines: [:browser]
+++
%{
ueberauth_failure: %Ueberauth.Failure{
errors: [
%Ueberauth.Failure.Error{
message: "Cross-Site Request Forgery attack",
message_key: :csrf_attack
}
],
provider: :github,
strategy: Ueberauth.Strategy.Github
}
}
+++
%{"code" => "908a69a812c17af0ab0b", "provider" => "github"}
+++
[info] Sent 302 in 4ms
[info] GET /
这是预期的吗?看起来我实际上已登录,因为如果我在浏览器中尝试相同的操作,则不必登录 GitHub。但是,还有一个 CRSF 失败正在发生,我不确定如何处理,并且无法从 conn.assigns 变量中获取我需要的信息。
任何帮助或建议将不胜感激!
答案 0 :(得分:0)
将 mix.exs 文件中的 ueberauth_github
更新为 latest 版本,例如 {:ueberauth_github, "~> 0.8"}
,然后运行 mix.deps update
(您可以从mix.deps clean
)。在此之后,我通过 Github 进行了身份验证,没有任何问题或额外的策略。在找到解决方案之前,我在对您的问题留下的评论中使用了该应用。