Code is community submitted, community supported, and recognized as ‘Use At Your Own Risk’.
Short Description
This is a proof of concept iRule to decode and validate a JWT submitted in the HTTP Authorization header. It supports only JWT’s signed with RS256 and was roughly tested with Azure, Okta and ADFS tokens.
It is not designed for production usage, especially there are more checks required to comply with https://datatracker.ietf.org/doc/html/rfc7519#section-7.2 .
Problem solved by this Code Snippet
Decode and validate a JWT with an iRule.
How to use this Code Snippet
Attach it to a VS and adapt the public key(s) and key id(s).
Code Snippet Meta Information
Version: POC
Coding Language: iRule
Full Code Snippet
# Code is community submitted, community supported, and recognized as ‘Use At Your Own Risk’.
when RULE_INIT priority 100 {
# SHA256 signing header
set static::jwt_validate_digest_header_sha256 "3031300d060960864801650304020105000420"
# Public key for signature validation
set static::jwt_validate_pubkey_kid1 {-----BEGIN PUBLIC KEY-----
XXX
-----END PUBLIC KEY-----
}
set static::jwt_validate_pubkey_kid2 {-----BEGIN PUBLIC KEY-----
XXX
-----END PUBLIC KEY-----
}
}
when HTTP_REQUEST priority 100 {
if { not ([HTTP::header value Authorization] starts_with "Bearer ") } {
HTTP::respond 401 content "Authorization required" "Content-Type" "text/plain" "WWW-Authenticate" "Bearer"
log local0. "No bearer token found"
This file has been truncated. show original
4 Likes
Thanks for sharing your efforts @Juergen_Mang !
True MVP!