Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
R

rails_warden

> 编程语言
Open source

A thin rails plugin on top of Warden for Authentication

164 stars0 likes2 views
WebsiteGitHub

About

A thin rails plugin on top of Warden for Authentication

Rails Warden

This application adds some nice helpers on-top of the base Warden Rack layer. It aims to make Warden easier to use in Rails-based environments without something as heavy-weight as devise.

Installation

Add this line to your application's Gemfile:

ruby
gem 'rails_warden'

And then execute

$ bundle

Or install it yourself as:

$ gem install rails_warden

Usage

Create a new Rails initializer to inject RailsWarden into the Rails middleware stack:

ruby
# config/initializers/warden.rb
Rails.configuration.middleware.use RailsWarden::Manager do |manager|
  manager.failure_app = Proc.new { |_env|
    ['401', {'Content-Type' => 'application/json'}, { error: 'Unauthorized', code: 401 }]
  }
  manager.default_strategies :password # needs to be defined
  # Optional Settings (see Warden wiki)
  # manager.scope_defaults :admin, strategies: [:password]
  # manager.default_scope = :admin # optional default scope
  # manager.intercept_401 = false # Warden will intercept 401 responses, which can cause conflicts
end

If you want to customize the Session serializer (optional), add the following to the intializer:

ruby
class Warden::SessionSerializer
  def serialize(record)
    [record.class.name, record.id]
  end

  def deserialize(keys)
    klass, id = keys
    klass.find_by(id: id)
  end
end

The next step is to configure warden with some authentication strategies. Check out the warden wiki for that.

Application Mixin

RailsWarden ships with a helpful set of methods and helpers for use inside of ActionController.

To use them, just include them inside your base controller.

ruby
class ApplicationController < ActionController::Base
  include RailsWarden::Authentication
end

Issues· 3 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Ruby

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 18, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言