forked from Github-Mirrors/canaille
feat: JSON HTTP errors on the OAuth endpoints
This commit is contained in:
parent
7493ce3c35
commit
b7bb14cfe7
2 changed files with 16 additions and 0 deletions
|
@ -15,6 +15,7 @@ from flask import request
|
|||
from flask import session
|
||||
from flask import url_for
|
||||
from werkzeug.datastructures import CombinedMultiDict
|
||||
from werkzeug.exceptions import HTTPException
|
||||
|
||||
from canaille import csrf
|
||||
from canaille.app import models
|
||||
|
@ -42,6 +43,14 @@ from .well_known import openid_configuration
|
|||
bp = Blueprint("endpoints", __name__, url_prefix="/oauth")
|
||||
|
||||
|
||||
@bp.errorhandler(HTTPException)
|
||||
def http_error_handler(error):
|
||||
return {
|
||||
"error": error.name.lower().replace(" ", "_"),
|
||||
"error_description": error.description,
|
||||
}, error.code
|
||||
|
||||
|
||||
@bp.route("/authorize", methods=["GET", "POST"])
|
||||
def authorize():
|
||||
current_app.logger.debug(
|
||||
|
|
7
tests/oidc/test_errors.py
Normal file
7
tests/oidc/test_errors.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
def test_json_oauth_errors(testclient):
|
||||
"""Checks that HTTP errors on the oauth endpoints are in the JSON format."""
|
||||
res = testclient.get("/oauth/invalid", status=404)
|
||||
assert res.json == {
|
||||
"error": "not_found",
|
||||
"error_description": "The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.",
|
||||
}
|
Loading…
Reference in a new issue