Skip to content

Commit

Permalink
content-type needs to have json in it to be handled
Browse files Browse the repository at this point in the history
  • Loading branch information
johanlundberg committed Jun 10, 2021
1 parent a8a9d56 commit eebf40c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/auth_server/middleware.py
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
import logging
from typing import Dict

from jwcrypto import jws
from pydantic import ValidationError
from starlette.datastructures import Headers
from starlette.middleware.base import BaseHTTPMiddleware
from starlette.requests import Request
from starlette.responses import PlainTextResponse
Expand Down Expand Up @@ -47,6 +49,10 @@ def __init__(self, app):

async def dispatch(self, request: Request, call_next):
if request.headers.get('content-type') == 'application/jose':
# Return a more helpful error message for a common mistake
return return_error_response(status_code=422, detail='content-type needs to be application/jose+json')

if request.headers.get('content-type') == 'application/jose+json':
config = load_config()
request = self.make_context_request(request)
logger.info('got application/jose request')
Expand Down
2 changes: 1 addition & 1 deletion src/auth_server/tests/test_app.py
Expand Up @@ -211,7 +211,7 @@ def test_transaction_jws(self):
)
data = _jws.serialize(compact=True)

client_header = {'Content-Type': 'application/jose'}
client_header = {'Content-Type': 'application/jose+json'}
response = self.client.post("/transaction", data=data, headers=client_header)

assert response.status_code == 200
Expand Down

0 comments on commit eebf40c

Please sign in to comment.