class Orion::Middleware::JWTAuth

Overview

JWT Token authentication Validates Bearer tokens in Authorization header

Usage: use Orion::Middleware::JWTAuth.new( secret: ENV["JWT_SECRET"], algorithm: :HS256 )

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(secret : String, algorithm : Symbol = :HS256, header_name : String = "Authorization") #

Class Method Detail

def self.generate_token(payload : Hash(String, JSON::Any), secret : String, algorithm : Symbol = :HS256, expires_in : Time::Span = 24.hours) : String #

Helper to generate JWT tokens


Instance Method Detail

def algorithm : Symbol #

def algorithm=(algorithm : Symbol) #

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

Override this to implement authentication logic


def header_name : String #

def header_name=(header_name : String) #

def secret : String #

def secret=(secret : String) #