LoginSignup
5
0

More than 5 years have passed since last update.

Phoenixアプリでbasic_authメモ

Posted at

モジュール

https://hexdocs.pm/basic_auth/readme.html
elixirのこのモジュールを利用してベーシック認証を設定する
基本はドキュメントの通りにすれば良いだけ

モジュールの追加

mix.exs
defp deps do
  [{:basic_auth, "~> 2.2"}]
end
mix deps.get

設定

config.exs
config :app_name, basic_auth: [
  realm: "Jirou",
  username: "myname",
  password: "pass"
]

configにアカウント設定したらbasic認証を追加したいコントローラで

test_controller.ex
defmodule TestController do

    plug BasicAuth, use_config: {: app_name, : basic_auth}

end

こうすることでbasic認証を追加することができる。

5
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
0