Forked from roblabla/caddy_verbose_auth_fail_config1.json5
Created
June 28, 2024 05:27
-
-
Save besrabasant/0701bdcc09c04f9155fc31df77e8a565 to your computer and use it in GitHub Desktop.
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
{ | |
// Disable admin for test | |
"admin": { | |
"disabled": true | |
}, | |
"apps": { | |
"http": { | |
// Use http to avoid having to provision an ssl cert | |
"http_port": 4444, | |
"servers": { | |
"srv0": { | |
"listen": [ | |
":4444" | |
], | |
// Simple authentication route that will invariably fail (since | |
// nothing is allowed) | |
"routes": [{ | |
"handle": [ | |
{ | |
"handler": "authentication", | |
"providers": { | |
"http_basic": {} | |
} | |
} | |
] | |
}], | |
// Based on the error code, we either want to redirect or return an | |
// error. | |
"errors": { | |
"routes": [{ | |
// Put status_code in the vars so we can access it from the | |
// vars matcher | |
"handle": [{ | |
"handler": "vars", | |
"status_code": "{http.error.status_code}" | |
}] | |
}, { | |
// If status code is 401, auth failed, do a redirect | |
"match": [{ | |
"vars": { "status_code": "401" } | |
}], | |
"handle": [{ | |
"handler": "static_response", | |
"status_code": "302", | |
"headers": { | |
"Location": ["/login"] | |
} | |
}], | |
"terminal": true | |
}, | |
{ | |
// If status code is not 401 and not empty, return the error code | |
// in the response | |
"match": [{ | |
"not": { | |
"vars": { | |
"status_code": "" | |
} | |
} | |
}], | |
"handle": [{ | |
"handler": "static_response", | |
"status_code": "{http.error.status_code}" | |
}], | |
"terminal": true | |
}, | |
{ | |
// If status code is empty (e.g. an error other than HandlerError | |
// was returned), return 500 | |
"handle": [{ | |
"handler": "static_response", | |
"status_code": "500" | |
}], | |
"terminal": true | |
}] | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment