Git Product home page Git Product logo

clearance_http_auth's Introduction

Clearance::HttpAuth

The goal of this project is simple, instant HTTP Basic Authentication for any controller in Rails 3 applications using Clearance for user authentication. You can use Clearance’s default, session based authentication in the user facing parts of your application, and use HTTP Basic Auth when connecting to it’s API.

It has two parts:

  1. A middleware which intercepts requests to your application API and performs a HTTP Basic Authentication by wrapping your application in a Rack::Auth::Basic block. It supplies the provided credentials to the User.authenticate method and sets an env['clearance.current_user'] variable.

  2. An overriden current_user helper method for controllers, which reads the variable set in the middleware.

Usage

First, add the gem to your Gemfile, along with clearance:

gem 'clearance', '~> 0.9.1'
gem 'clearance_http_auth'

Second, include the module in your ApplicationController (or in a specific controller) after you include Clearance::Authentication:

class ApplicationController < ActionController::Base
  include Clearance::Authentication
  include Clearance::HttpAuth
end

There is no step three. When you hit your application API with the same credentials as when logging in the browser, you should be in:

$ curl -i -X GET  -u [email protected]:password http://localhost:3000/books.xml
$ curl -i -X POST -u [email protected]:password -H "Content-Type: application/xml" http://localhost:3000/books.xml \
       -d "<book><author>Kafka</author><title>Metamorphosis</title></book>"

By default, the middleware intercepts only requests to JSON and XML formats. You can add more formats in your config/application.rb:

config.clearance_http_auth.api_formats << 'csv'

About

The project originally grew out of a simple monkeypatch: github.com/thoughtbot/clearance/issues/34

Comments and patches are welcome. Fork, add tests for features and don’t break any existing ones, send a pull request.


Karel Minarik (karmi.cz)

clearance_http_auth's People

Contributors

jtreitz avatar karmi avatar

Stargazers

 avatar  avatar

Watchers

 avatar

Forkers

kraxnet jhny

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.