0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ruby on RailsでBasic認証を実装する方法

Posted at

Ruby on RailsでBasic認証を実装する方法について説明します。

Basic認証とは

HTTP通信の規格に備え付けられているユーザー認証の仕組み
サーバーと通信が可能なユーザーとパスワードがあらかじめ設定されており、それを知るユーザーのみがアプリケーションを利用できる仕組み

導入方法

Ruby on RailsにはBasic認証を導入する為のメソッドが用意されている
メソッド authenticate_or_request_with_http_basic

authenticate_or_request_with_http_basic do |username, password|
  username == '設定したいユーザー名' && password == '設定したいパスワード'
end

これで実装できます。 Basic認証のログイン要求を全てのコントローラで行う場合が多いと思うのでbefore_actionに設定しとくと良いかもです!

0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?