Authlogic - authentication using basic HTTP authentication

I want to use "authenticate_ with_ http_ basic", but I just can't get it working.

In my RoR application Authlogic works fine, and I use user sessions for this. Saving this method as of now, I need to use authenticate_with_http_basic. I have an iPhone SDK application, and now I need to take some products from my web application and display it as a list. Therefore, I assume that I need to send a request to my webapp like this; http: // username: password@192.168.1.9 / products /

So my question is to check this username and password and what do I need to do for my UserSession Controller?

+3
source share
2 answers

You do not need to do anything with UserSessionController, since this controller will only process registration and logout.

Authlogic and are authenticate_with_http_basicnot related to each other. If you want to authenticate through HTTP basic, you just need to create an authentication method using the method provided by Rails and put this method in before_filter. When logging in through HTTP authentication, I assume that the username and password should be required for each request.

So yours ProductsControllerwill be something like this

class ProductsController < ApplicationController
  before_filter :authenticate_via_http_basic

  # In case you have some method to redirect user to login page, skip it
  skip_before_filter :require_authentication

  ...

  protected

  def authenticate_via_http_basic
    unless current_user
      authenticate_with_http_basic do |username, password|
        if user = User.find_by_username(username)
          user.valid_password?(password)
        else
          false
        end
      end
    end
  end
+5
source

Auth over HTTP Auth is now integrated into AuthLogic and is enabled by default.

+1
source

Source: https://habr.com/ru/post/1720757/


All Articles