Skip to content

Commit 6da8a63

Browse files
authored
Merge pull request #1 from felixb/optional-issuer-audience
Optional issuer and audience verification
2 parents 73a88c3 + 15e550d commit 6da8a63

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

haproxy-example.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ global
66
# Path to public key certificate tokens are signed with (get from your token issuer, like auth0.com):
77
setenv OAUTH_PUBKEY_PATH /etc/haproxy/pem/pubkey.pem
88

9-
# OAuth issuer
9+
# OPTIONAL: OAuth issuer
1010
setenv OAUTH_ISSUER https://youraccount.auth0.com/
1111

12-
# OAuth audience - should match what you set on the Auth0 website for your API
12+
# OPTIONAL: OAuth audience - should match what you set on the Auth0 website for your API
1313
setenv OAUTH_AUDIENCE https://api.mywebsite.com
1414

1515
defaults

lib/jwtverify.lua

+5-5
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ function jwtverify(txn)
151151
end
152152

153153
-- 5. Verify the issuer
154-
if issuerIsValid(token, issuer) == false then
154+
if issuer ~= nil and issuerIsValid(token, issuer) == false then
155155
log("Issuer not valid.")
156156
goto out
157157
end
158158

159159
-- 6. Verify the audience
160-
if audienceIsValid(token, audience) == false then
160+
if audience ~= nil and audienceIsValid(token, audience) == false then
161161
log("Audience not valid.")
162162
goto out
163163
end
@@ -166,7 +166,7 @@ function jwtverify(txn)
166166
if token.payloaddecoded.scope ~= nil then
167167
txn.set_var(txn, "txn.oauth_scopes", token.payloaddecoded.scope)
168168
else
169-
txn.set_var(txn, "txn.oauth_scopes", "")
169+
txn.set_var(txn, "txn.oauth_scopes", "")
170170
end
171171

172172
-- 8. Set authorized variable
@@ -192,8 +192,8 @@ core.register_init(function()
192192
config.audience = os.getenv("OAUTH_AUDIENCE")
193193

194194
log("PublicKeyPath: " .. publicKeyPath)
195-
log("Issuer: " .. config.issuer)
196-
log("Audience: " .. config.audience)
195+
log("Issuer: " .. (config.issuer or "<none>"))
196+
log("Audience: " .. (config.audience or "<none>"))
197197
end)
198198

199199
-- Called on a request.

0 commit comments

Comments
 (0)