SlideShare a Scribd company logo
Valentyn Ostakh
https://github.com/valikos
https://twitter.com/valikos_ost
Rodauth
Clean Authentication
What is the most
necessary feature for
interaction with users?
Authentication
Authentication is the act of
identification of user that going
to interact with your product
I want authentication
for my application
Rodauth: Clean Authentication - Valentine Ostakh
Ruby-toolbox
Awesome-ruby
Authentication
• Authlogic
• Devise
• Clearance
• Sorcery
• Warden
• Rodauth
What about custom
solution?
Rodauth: Clean Authentication - Valentine Ostakh
Rodauth: Clean Authentication - Valentine Ostakh
Custom Solution vs
Authentication Libraries
Library Issues Pull Requests First Release
Sorcery 64/451 28/306 31 Jan 2011
Clearance 12/374 4/369 1 Sep 2009
Authlogic 124/221 6/186 3 Nov 2008
Devise 39/3353 29/979 21 Oct 2009
Warden 18/74 4/49 26 May 2009
Rodauth 0/8 0/11 12 Aug 2015
I want flexible
authentication that can be
used with any framework
Rodauth: Clean Authentication - Valentine Ostakh
Rodauth: Clean Authentication - Valentine Ostakh
Rodauth: Clean Authentication - Valentine Ostakh
How to choose a library
for my application?
Dependencies
• Authlogic - activerecord, activesupport
• Devise - rails, warden
• Clearance - rails, rack
• Sorcery - rails
• Warden - rack
• Rodauth - roda, rack
Clearance
Features
Registration
• Authlogic
• Devise
• Clearance
• Sorcery
• Warden
• Rodauth
Login
• Authlogic
• Devise
• Clearance
• Sorcery
• Warden
• Rodauth
Logout
• Authlogic
• Devise
• Clearance
• Sorcery
• Warden
• Rodauth
Would be great to have
token authentication
Token Authentication
• Authlogic
• Devise
• Clearance
• Sorcery
• Warden
• Rodauth
Token Authentication
Articles
• An Introduction to Using JWT Authentication in Rails
• Authenticate Your Rails API with JWT from Scratch
• Token-based authentication with Ruby on Rails 5 API
• JWT Auth in Rails, From Scratch
• Implementing JWT in Ruby on Rails-based API
• Authenticate Your Rails API with JWT
• Rails Api Backed With JWT
• Rails, Devise, JWT and the forgotten Warden
Token Authentication

Gems
• jwt_authentication
• simple_token_authentication
• devise_token_auth
Token Authentication

Gems
• jwt_authentication (based on devise)
• simple_token_authentication (based on devise)
• devise_token_auth (based on devise)
Token Authentication
Popularity
Library
Total Downloads
rubygems.org
Devise 21,407,462
Warden 21,018,495
Authlogic 2,343,678
Sorcery 527,431
Clearance 317,409
Rodauth 6,163
Summary
Library Dependencies Features
Token

Authentication
Devise
Warden
Authlogic
Sorcery
Clearance
Rodauth
Rodauth
Rodauth
Jeremy Evans
Twitter: @jeremyevans0
Roda
Sequel
Rodauth Goals
• Security
• Simplicity
• Flexibility
Features first
Rodauth Features
Login
Rodauth Features
Login
Logout
Rodauth Features
Login
Logout
Change Password
Rodauth Features
Login
Logout
Change Password
Change Login
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Verify Account Grace Period
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Verify Account Grace Period
Password Grace Period
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Verify Account Grace Period
Password Grace Period
Password Complexity
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Verify Account Grace Period
Password Grace Period
Password Complexity
Disallow Password Reuse
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Verify Account Grace Period
Password Grace Period
Password Complexity
Disallow Password Reuse
Password Expiration
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Verify Account Grace Period
Password Grace Period
Password Complexity
Disallow Password Reuse
Password Expiration
Account Expiration
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Verify Account Grace Period
Password Grace Period
Password Complexity
Disallow Password Reuse
Password Expiration
Account Expiration
Session Expiration
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Verify Account Grace Period
Password Grace Period
Password Complexity
Disallow Password Reuse
Password Expiration
Account Expiration
Session Expiration
Single Session
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Verify Account Grace Period
Password Grace Period
Password Complexity
Disallow Password Reuse
Password Expiration
Account Expiration
Session Expiration
Single Session
JWT
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Verify Account Grace Period
Password Grace Period
Password Complexity
Disallow Password Reuse
Password Expiration
Account Expiration
Session Expiration
Single Session
JWT
Update Password Hash
Rodauth Features
Login
Logout
Change Password
Change Login
Reset Password
Create Account
Close Account
Verify Account
Confirm Password
Remember (Autologin via token)
Lockout (Bruteforce protection)
OTP (2 factor authentication via TOTP)
Recovery Codes (2 factor authentication via backup codes)
SMS Codes (2 factor authentication via SMS)
Verify Change Login
Verify Account Grace Period
Password Grace Period
Password Complexity
Disallow Password Reuse
Password Expiration
Account Expiration
Session Expiration
Single Session
JWT
Update Password HashHTTP Basic Auth
Rodauth: Clean Authentication - Valentine Ostakh
Security
• Uses database functions to access password
hashes
• Two database accounts are used
• Uses database functions to access password
hashes (optional)
• Two database accounts are used (optional)
Flexibility
Can be used with the
any rack framework
require "roda"
class RodauthApp < Roda
# If using Rodauth in a non-Roda application
# plugin :middleware
plugin :rodauth do
enable :login, :logout, :change_password
end
route do |r|
r.rodauth
rodauth.require_authentication
# If using Rodauth in a Roda application
# Your app code here
end
end
# If using Rodauth in a non-Roda application
# use RodauthApp
# If using Rodauth in a Roda application
run RodauthApp
require "roda"
class RodauthApp < Roda
# If using Rodauth in a non-Roda application
# plugin :middleware
plugin :rodauth do
enable :login, :logout, :change_password
end
route do |r|
r.rodauth
rodauth.require_authentication
# If using Rodauth in a Roda application
# Your app code here
end
end
# If using Rodauth in a non-Roda application
# use RodauthApp
# If using Rodauth in a Roda application
run RodauthApp
Rodauth uses a simple
configuration DSL
require 'simple_ldap_authenticator'
plugin :rodauth do
enable :login, :logout
# Don't require the bcrypt library, since using LDAP for auth
require_bcrypt? false
# Treat the login itself as the account
account_from_login{|l| l.to_s}
# Use the login provided as the session value
account_session_value{account}
# Store session value in :login key, since the :account_id
# default wouldn't make sense
session_key :login
password_match? do |password|
SimpleLdapAuthenticator.valid?(account, password)
end
end
Simplicity
Rodauth allows for
overriding any part of the
framework
module Auth
class Rodauth < Roda
plugin :rodauth do
enable :login
end
route do |r|
r.post 'login' do
# Custom POST /login handling here
end
r.rodauth
end
end
end
How to start use
Rodauth?
• Resolve database dependencies
• Define Rodauth features
Database
dependencies
• Setup database
• Create tables
Setup With Postgresql
# Load extentions
psql -U postgres -c "CREATE EXTENSION citext" ${DATABASE_NAME}
# Create database accounts
createuser -U postgres ${DATABASE_NAME}
createuser -U postgres ${DATABASE_NAME}_password
Setup With Postgresql
create_table(:accounts) do
primary_key :id, :type=>:Bignum
foreign_key :status_id, :account_statuses, :null=>false, :default=>1
if db.database_type == :postgres
citext :email, :null=>false
constraint :valid_email, :email=>/^[^,;@ rn]+@[^,@; rn]+.[^,@; rn]+$/
index :email, :unique=>true, :where=>{:status_id=>[1, 2]}
else
String :email, :null=>false
index :email, :unique=>true
end
end
case database_type
when :postgres
user = get{Sequel.lit('current_user')} + '_password'
run "GRANT REFERENCES ON accounts TO #{user}"
end
Define Rodauth Features
plugin :rodauth, :json=>true, :csrf=>false, :flash=>false do
enable :change_password, :close_account, :create_account,
:login, :logout, :remember, :reset_password, :verify_account,
:otp, :recovery_codes, :sms_codes, :password_complexity,
:disallow_password_reuse, :password_grace_period,
:account_expiration, :single_session, :jwt, :session_expiration,
max_invalid_logins 2
allow_password_change_after 60
verify_account_grace_period 300
jwt_secret secret
sms_send do |phone_number, message|
MUTEX.synchronize{SMS[session_value] = "..."}
end
end
Summary
Rodauth Advantages
• Integration with any rack application
• Minimun dependencies
• Features
• Security
• Simplicity
Rodauth Disadvantages
• Doesn’t work with OAuth
• Routes design: can mismatch with your design
My own experience
Registration
module Auth
class Rodauth < Roda
DB = Sequel.connect(ENV['DATABASE_URL'])
plugin :middleware
plugin :rodauth, json: :only do
enable :login, :logout, :jwt, :create_account
jwt_session_hash do
super().merge(exp: SmartTaskApi::Utils.jwt_expiration)
end
jwt_secret ENV['JWT_SECRET']
end
route do |r|
r.rodauth
env['rodauth'] = rodauth
end
end
end
Token Authentication
module Api
class Rodauth < Roda
DB = Sequel.connect(ENV['DATABASE_URL'])
plugin :middleware
plugin :rodauth, json: :only do
enable :jwt
jwt_secret ENV['JWT_SECRET']
end
route do |r|
r.rodauth
rodauth.require_authentication
env['rodauth'] = rodauth
end
end
end
Rodauth Examples
• https://github.com/jeremyevans/ginatra
• https://github.com/jeremyevans/rodauth-demo-rails
• https://github.com/davydovanton/rodauth_hanami
• https://github.com/davydovanton/grape-rodauth
• https://github.com/valikos/smart-task-api-hanami
Rodauth
Clean Authentication
Thanks!
Questions?
Valentyn Ostakh
https://github.com/valikos
https://twitter.com/valikos_ost

More Related Content

PPTX
Lecture 20101124
PDF
Saml authentication bypass
KEY
OAuth using PHP5
PDF
Implementing OAuth with PHP
PPTX
Building Secure User Interfaces With JWTs
PDF
Ember Authentication and Authorization with Torii
PDF
Funtional Ruby - Mikhail Bortnyk
PDF
Ruby Gems and Native Extensions - Stas Volovyk
Lecture 20101124
Saml authentication bypass
OAuth using PHP5
Implementing OAuth with PHP
Building Secure User Interfaces With JWTs
Ember Authentication and Authorization with Torii
Funtional Ruby - Mikhail Bortnyk
Ruby Gems and Native Extensions - Stas Volovyk

More from Ruby Meditation (20)

PDF
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
PDF
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
PDF
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
PDF
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
PDF
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
PDF
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
PDF
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
PDF
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
PDF
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
PDF
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
PDF
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
PDF
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
PDF
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
PDF
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
PDF
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
PDF
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
PDF
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
PDF
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
PDF
Rails App performance at the limit - Bogdan Gusiev
PDF
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
Is this Legacy or Revenant Code? - Sergey Sergyenko | Ruby Meditation 30
Life with GraphQL API: good practices and unresolved issues - Roman Dubrovsky...
Where is your license, dude? - Viacheslav Miroshnychenko | Ruby Meditation 29
Dry-validation update. Dry-validation vs Dry-schema 1.0 - Aleksandra Stolyar ...
How to cook Rabbit on Production - Bohdan Parshentsev | Ruby Meditation 28
How to cook Rabbit on Production - Serhiy Nazarov | Ruby Meditation 28
Reinventing the wheel - why do it and how to feel good about it - Julik Tarkh...
Performance Optimization 101 for Ruby developers - Nihad Abbasov (ENG) | Ruby...
Use cases for Serverless Technologies - Ruslan Tolstov (RUS) | Ruby Meditatio...
The Trailblazer Ride from the If Jungle into a Civilised Railway Station - Or...
What/How to do with GraphQL? - Valentyn Ostakh (ENG) | Ruby Meditation 27
New features in Rails 6 - Nihad Abbasov (RUS) | Ruby Meditation 26
Security Scanning Overview - Tetiana Chupryna (RUS) | Ruby Meditation 26
Teach your application eloquence. Logs, metrics, traces - Dmytro Shapovalov (...
Best practices. Exploring - Ike Kurghinyan (RUS) | Ruby Meditation 26
Road to A/B testing - Alexey Vasiliev (ENG) | Ruby Meditation 25
Concurrency in production. Real life example - Dmytro Herasymuk | Ruby Medita...
Data encryption for Ruby web applications - Dmytro Shapovalov (RUS) | Ruby Me...
Rails App performance at the limit - Bogdan Gusiev
GDPR. Next Y2K in 2018? - Anton Tkachov | Ruby Meditation #23
Ad

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Electronic commerce courselecture one. Pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Approach and Philosophy of On baking technology
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Encapsulation theory and applications.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Machine learning based COVID-19 study performance prediction
Building Integrated photovoltaic BIPV_UPV.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
MYSQL Presentation for SQL database connectivity
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Electronic commerce courselecture one. Pdf
NewMind AI Weekly Chronicles - August'25 Week I
Encapsulation_ Review paper, used for researhc scholars
Approach and Philosophy of On baking technology
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
CIFDAQ's Market Insight: SEC Turns Pro Crypto
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Encapsulation theory and applications.pdf
Network Security Unit 5.pdf for BCA BBA.
20250228 LYD VKU AI Blended-Learning.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Ad

Rodauth: Clean Authentication - Valentine Ostakh