如何在 Elixir 中为 Uberauth 添加状态参数

how to add state param for Uberauth in Elixir

在 oAuth 过程中,最好设置状态参数以授权 url 以确保安全。当我检查 Überauth Shopify https://github.com/kodehort/ueberauth_shopify/blob/master/lib/ueberauth/strategy/shopify.ex#L88 时,它被发送到 shopify。

但我不明白我需要如何在我的 Phoenix 应用程序中设置此状态参数,Shopify 才能获取它。有什么建议吗?

您在要传递给 Ueberauth 的 URL 中提供 state(同样,scopes 也被传递)

取决于您的路由器设置,默认设置为:

pipeline :auth do
  Ueberauth.plug "/auth"
end

scope "/auth" do
  pipe_through [:browser, :auth]

  get "/:provider/callback", AuthController, :callback
end

您通过将用户重定向到指定的身份验证来提供 scopesstate URL:

/auth/shopify?scopes=read_orders%20read_products&state=yourSuperSecretState

或没有任何作用域:

/auth/shopify?state=yourSuperSecretState

Since recent, Ueberauth auto-sets and checks it for you by default, to protect you from CSRF.