【发布时间】:2019-01-18 05:57:42
【问题描述】:
在我的 Phoenix 应用程序中,我有一个管道和范围“api”
pipeline :api do
plug(:accepts, ["json"])
end
scope "/api" .....
# .....
end
如何通过通过特殊标头传递的 API 密钥保护它?也就是说,我想要这样的东西:
defmodule MyApp.MyController do
use MyApp.Web, :controller
:before_filter :authenticate_user_by_api_key!
def authenticate_user_by_api_key!(conn, params) do
# check if a header exists and key is valid
end
end
我正计划验证一个标题。 如何在不依赖任何第三方库的情况下做到这一点?
还有。如果我想使用 模块 而不是单个函数,我该怎么做?
【问题讨论】:
标签: rest elixir phoenix-framework