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") #

[View source]

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


[View source]

Instance Method Detail

def algorithm : Symbol #

[View source]
def algorithm=(algorithm : Symbol) #

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

Override this to implement authentication logic


[View source]
def header_name : String #

[View source]
def header_name=(header_name : String) #

[View source]
def secret : String #

[View source]
def secret=(secret : String) #

[View source]