class Orion::Middleware::SessionAuth

Overview

Session-based authentication Checks for user_id in session

Usage: use Orion::Middleware::SessionAuth.new( session_key: :user_id, redirect_to: "/login" # optional redirect instead of 401 )

Defined in:

orion/middleware/auth.cr

Constructors

Class Method Summary

Instance Method Summary

Instance methods inherited from class Orion::Middleware::Auth

authenticate(context : Orion::Server::Context) : Bool authenticate, call(context : HTTP::Server::Context) call, unauthorized_response(context : Orion::Server::Context) unauthorized_response

Constructor Detail

def self.new(session_key : String | Symbol = :user_id, redirect_to : String | Nil = nil) #

Class Method Detail

def self.login(context : Orion::Server::Context, user_id : String | Int, key : String | Symbol = :user_id) #

Helper to set authenticated user


def self.logout(context : Orion::Server::Context, key : String | Symbol = :user_id) #

Helper to logout


def self.user_id(context : Orion::Server::Context, key : String | Symbol = :user_id) : String | Nil #

Helper to get authenticated user ID


Instance Method Detail

def authenticate(context : Orion::Server::Context) : Bool #
Description copied from class Orion::Middleware::Auth

Override this to implement authentication logic


def redirect_to : String | Nil #

def redirect_to=(redirect_to : String | Nil) #

def session_key : String | Symbol #

def session_key=(session_key : String | Symbol) #

def unauthorized_response(context : Orion::Server::Context) #
Description copied from class Orion::Middleware::Auth

Override to customize unauthorized response