Slide 1

Slide 1 text

Valentyn Ostakh https://github.com/valikos https://twitter.com/valikos_ost

Slide 2

Slide 2 text

Rodauth Clean Authentication

Slide 3

Slide 3 text

What is the most necessary feature for interaction with users?

Slide 4

Slide 4 text

Authentication

Slide 5

Slide 5 text

Authentication is the act of identification of user that going to interact with your product

Slide 6

Slide 6 text

I want authentication for my application

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Ruby-toolbox

Slide 9

Slide 9 text

Awesome-ruby

Slide 10

Slide 10 text

Authentication • Authlogic • Devise • Clearance • Sorcery • Warden • Rodauth

Slide 11

Slide 11 text

What about custom solution?

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

I want flexible authentication that can be used with any framework

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

How to choose a library for my application?

Slide 20

Slide 20 text

Dependencies

Slide 21

Slide 21 text

• Authlogic - activerecord, activesupport • Devise - rails, warden • Clearance - rails, rack • Sorcery - rails • Warden - rack • Rodauth - roda, rack

Slide 22

Slide 22 text

Clearance

Slide 23

Slide 23 text

Features

Slide 24

Slide 24 text

Registration • Authlogic • Devise • Clearance • Sorcery • Warden • Rodauth

Slide 25

Slide 25 text

Login • Authlogic • Devise • Clearance • Sorcery • Warden • Rodauth

Slide 26

Slide 26 text

Logout • Authlogic • Devise • Clearance • Sorcery • Warden • Rodauth

Slide 27

Slide 27 text

Would be great to have token authentication

Slide 28

Slide 28 text

Token Authentication • Authlogic • Devise • Clearance • Sorcery • Warden • Rodauth

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

Token Authentication
 Gems • jwt_authentication • simple_token_authentication • devise_token_auth

Slide 31

Slide 31 text

Token Authentication
 Gems • jwt_authentication (based on devise) • simple_token_authentication (based on devise) • devise_token_auth (based on devise)

Slide 32

Slide 32 text

Token Authentication

Slide 33

Slide 33 text

Popularity

Slide 34

Slide 34 text

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

Slide 35

Slide 35 text

Summary

Slide 36

Slide 36 text

Library Dependencies Features Token
 Authentication Devise Warden Authlogic Sorcery Clearance Rodauth

Slide 37

Slide 37 text

Rodauth

Slide 38

Slide 38 text

Rodauth

Slide 39

Slide 39 text

Jeremy Evans Twitter: @jeremyevans0

Slide 40

Slide 40 text

Roda Sequel

Slide 41

Slide 41 text

Rodauth Goals • Security • Simplicity • Flexibility

Slide 42

Slide 42 text

Features first

Slide 43

Slide 43 text

Rodauth Features Login

Slide 44

Slide 44 text

Rodauth Features Login Logout

Slide 45

Slide 45 text

Rodauth Features Login Logout Change Password

Slide 46

Slide 46 text

Rodauth Features Login Logout Change Password Change Login

Slide 47

Slide 47 text

Rodauth Features Login Logout Change Password Change Login Reset Password

Slide 48

Slide 48 text

Rodauth Features Login Logout Change Password Change Login Reset Password Create Account

Slide 49

Slide 49 text

Rodauth Features Login Logout Change Password Change Login Reset Password Create Account Close Account

Slide 50

Slide 50 text

Rodauth Features Login Logout Change Password Change Login Reset Password Create Account Close Account Verify Account

Slide 51

Slide 51 text

Rodauth Features Login Logout Change Password Change Login Reset Password Create Account Close Account Verify Account Confirm Password

Slide 52

Slide 52 text

Rodauth Features Login Logout Change Password Change Login Reset Password Create Account Close Account Verify Account Confirm Password Remember (Autologin via token)

Slide 53

Slide 53 text

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)

Slide 54

Slide 54 text

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)

Slide 55

Slide 55 text

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)

Slide 56

Slide 56 text

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)

Slide 57

Slide 57 text

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

Slide 58

Slide 58 text

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

Slide 59

Slide 59 text

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

Slide 60

Slide 60 text

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

Slide 61

Slide 61 text

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

Slide 62

Slide 62 text

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

Slide 63

Slide 63 text

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

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

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

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

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 HTTP Basic Auth

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

Security

Slide 71

Slide 71 text

• Uses database functions to access password hashes • Two database accounts are used

Slide 72

Slide 72 text

• Uses database functions to access password hashes (optional) • Two database accounts are used (optional)

Slide 73

Slide 73 text

Flexibility

Slide 74

Slide 74 text

Can be used with the any rack framework

Slide 75

Slide 75 text

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

Slide 76

Slide 76 text

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

Slide 77

Slide 77 text

Rodauth uses a simple configuration DSL

Slide 78

Slide 78 text

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

Slide 79

Slide 79 text

Simplicity

Slide 80

Slide 80 text

Rodauth allows for overriding any part of the framework

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

How to start use Rodauth?

Slide 83

Slide 83 text

• Resolve database dependencies • Define Rodauth features

Slide 84

Slide 84 text

Database dependencies

Slide 85

Slide 85 text

• Setup database • Create tables

Slide 86

Slide 86 text

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

Slide 87

Slide 87 text

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=>/^[^,;@ \r\n]+@[^,@; \r\n]+\.[^,@; \r\n]+$/ 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

Slide 88

Slide 88 text

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

Slide 89

Slide 89 text

Summary

Slide 90

Slide 90 text

Rodauth Advantages • Integration with any rack application • Minimun dependencies • Features • Security • Simplicity

Slide 91

Slide 91 text

Rodauth Disadvantages • Doesn’t work with OAuth • Routes design: can mismatch with your design

Slide 92

Slide 92 text

My own experience

Slide 93

Slide 93 text

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

Slide 94

Slide 94 text

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

Slide 95

Slide 95 text

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

Slide 96

Slide 96 text

Rodauth Clean Authentication

Slide 97

Slide 97 text

Thanks!

Slide 98

Slide 98 text

Questions?

Slide 99

Slide 99 text

Valentyn Ostakh https://github.com/valikos https://twitter.com/valikos_ost