Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not read from request body unless we have to #35

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions oauth2app/authenticate.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class Authenticator(object):
the scope the authenticator will authenticate.
*Default None*
* *authentication_method:* Accepted authentication methods. Possible
values are: oauth2app.consts.MAC, oauth2app.consts.BEARER,
oauth2app.consts.MAC | oauth2app.consts.BEARER,
values are: oauth2app.consts.MAC, oauth2app.consts.BEARER,
oauth2app.consts.MAC | oauth2app.consts.BEARER,
*Default oauth2app.consts.BEARER*

"""
Expand All @@ -61,15 +61,16 @@ class Authenticator(object):
access_token = None
auth_type = None
auth_value = None
bearer_token = None
error = None
attempted_validation = False

def __init__(
self,
scope=None,
authentication_method=AUTHENTICATION_METHOD):
self,
scope=None,
authentication_method=AUTHENTICATION_METHOD):
if authentication_method not in [BEARER, MAC, BEARER | MAC]:
raise OAuth2Exception("Possible values for authentication_method"
raise OAuth2Exception("Possible values for authentication_method"
" are oauth2app.consts.MAC, oauth2app.consts.BEARER, "
"oauth2app.consts.MAC | oauth2app.consts.BEARER")
self.authentication_method = authentication_method
Expand All @@ -90,11 +91,12 @@ def validate(self, request):

*Returns None*"""
self.request = request
self.bearer_token = request.REQUEST.get('bearer_token')
if "HTTP_AUTHORIZATION" in self.request.META:
auth = self.request.META["HTTP_AUTHORIZATION"].split()
self.auth_type = auth[0].lower()
self.auth_value = " ".join(auth[1:]).strip()
else:
self.bearer_token = self.request.REQUEST.get('bearer_token')
self.request_hostname = self.request.META.get("REMOTE_HOST")
self.request_port = self.request.META.get("SERVER_PORT")
try:
Expand Down Expand Up @@ -166,7 +168,7 @@ def _validate_mac(self, mac_header):
nonce_timestamp, nonce_string = mac_header["nonce"].split(":")
mac = sha256("\n".join([
mac_header["nonce"], # The nonce value generated for the request
self.request.method.upper(), # The HTTP request method
self.request.method.upper(), # The HTTP request method
"XXX", # The HTTP request-URI
self.request_hostname, # The hostname included in the HTTP request
self.request_port, # The port as included in the HTTP request
Expand All @@ -185,7 +187,7 @@ def _validate_mac(self, mac_header):
# the determination of staleness is left up to the server to
# define).
# 3. Verify the scope and validity of the MAC credentials.


def _get_user(self):
"""The user associated with the valid access token.
Expand Down Expand Up @@ -279,16 +281,16 @@ class JSONAuthenticator(Authenticator):

* *scope:* A iterable of oauth2app.models.AccessRange objects.
"""

callback = None

def __init__(self, scope=None):
Authenticator.__init__(self, scope=scope)

def validate(self, request):
self.callback = request.REQUEST.get('callback')
return Authenticator.validate(self, request)

def response(self, data):
"""Returns a HttpResponse object of JSON serialized data.

Expand Down