From c432e7819fb00a2624f16e573d6b028f2470dcc7 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 24 Sep 2017 21:48:09 +0200 Subject: [PATCH] Add endpoint for Bearer authentication Closes #385 --- httpbin/core.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/httpbin/core.py b/httpbin/core.py index 73adcb6..f9ebfe2 100644 --- a/httpbin/core.py +++ b/httpbin/core.py @@ -454,6 +454,20 @@ def hidden_basic_auth(user='user', passwd='passwd'): return jsonify(authenticated=True, user=user) +@app.route('/bearer') +def bearer_auth(): + """Authenticates using bearer authentication.""" + if 'Authorization' not in request.headers: + response = app.make_response('') + response.headers['WWW-Authenticate'] = 'Bearer' + response.status_code = 401 + return response + authorization = request.headers.get('Authorization') + token = authorization.lstrip('Bearer ') + + return jsonify(authenticated=True, token=token) + + @app.route('/digest-auth///') def digest_auth_md5(qop=None, user='user', passwd='passwd'): return digest_auth(qop, user, passwd, "MD5", 'never')