-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement token revocation and validation
Introduced the capability to revoke tokens and ensure their validity by adding a JTI provider and corresponding methods. The JTI (JWT ID) is used to uniquely identify each token, allowing for efficient tracking and revocation. The configuration now includes an issuer for token issuance, enhancing security and allowing for issuer-specific checks. Unit tests have been added to ensure proper functionality of the revoke and valid methods. This improves the system's security by preventing the use of revoked tokens.
- Loading branch information
Showing
6 changed files
with
111 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
module Authly | ||
class Configuration | ||
property issuer : String = "The Authority Server Provider" | ||
property secret_key : String = Random::Secure.hex(16) | ||
property public_key : String = Random::Secure.hex(16) | ||
property refresh_ttl : Time::Span = 1.day | ||
property code_ttl : Time::Span = 5.minutes | ||
property access_ttl : Time::Span = 1.hour | ||
property owners : AuthorizableOwner = Owners.new | ||
property clients : AuthorizableClient = Clients.new | ||
property jti_provider : JTIProvider = InMemoryJTIProvider.new | ||
property algorithm : JWT::Algorithm = JWT::Algorithm::HS256 | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
module Authly | ||
class InMemoryJTIProvider | ||
include Authly::JTIProvider | ||
include Enumerable(String) | ||
|
||
# Use a set to track revoked tokens by their jti | ||
def initialize | ||
@revoked_tokens = Set(String).new | ||
end | ||
|
||
# Implement the each method to make the class enumerable | ||
def each | ||
@revoked_tokens.each { |jti| yield jti } | ||
end | ||
|
||
# Method to revoke a token by its jti | ||
def revoke(jti : String) | ||
@revoked_tokens.add(jti) | ||
end | ||
|
||
# Method to check if a token's jti has been revoked | ||
def revoked?(jti : String) : Bool | ||
any? { |revoked_jti| revoked_jti == jti } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module Authly | ||
module JTIProvider | ||
abstract def revoke(jti : String) | ||
abstract def revoked?(jti : String) : Bool | ||
end | ||
end |