Fix OAuth 2 handler to support retrieving parameters from other places; various OAuth client (such as the Go library) send the values in the request body or even the Auth header

This commit is contained in:
Joseph Schorr 2015-05-18 12:38:39 -04:00
parent 91b464d0de
commit fb8e718c44
3 changed files with 35 additions and 14 deletions

16
util/headers.py Normal file
View file

@ -0,0 +1,16 @@
import base64
def parse_basic_auth(header_value):
""" Attempts to parse the given header value as a Base64-encoded Basic auth header. """
if not header_value:
return None
parts = header_value.split(' ')
if len(parts) != 2 or parts[0].lower() != 'basic':
return None
try:
return base64.b64decode(parts[1])
except ValueError:
return None