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

Fixed Form UrlEncoded OAuth Lib Core #1382

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Changes from 2 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
19 changes: 18 additions & 1 deletion oauth2_provider/oauth2_backends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
import json
from urllib.parse import urlparse, urlunparse
from urllib.parse import unquote, urlparse, urlunparse

from oauthlib import oauth2
from oauthlib.common import Request as OauthlibRequest
Expand Down Expand Up @@ -238,6 +239,22 @@
return body


class JSONAndFormUrlencodedOAuthLibCore(JSONOAuthLibCore):
def extract_body(self, request):
# fixes base64 encoded form-submission. you can't control what all oauth clients use.
# if request.content_type in ['multipart/form-data', 'application/x-www-form-urlencoded']:
ferrants marked this conversation as resolved.
Show resolved Hide resolved
if request.content_type in ["application/x-www-form-urlencoded"]:
query_string = base64.b64decode(request.body).decode("utf-8")
query_params = {p.split("=")[0]: p.split("=")[1] for p in query_string.split("&")}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a safer way to do this

if "redirect_uri" in query_params:
query_params["redirect_uri"] = unquote(query_params["redirect_uri"])
ferrants marked this conversation as resolved.
Show resolved Hide resolved
res = query_params.items()

Check warning on line 251 in oauth2_provider/oauth2_backends.py

View check run for this annotation

Codecov / codecov/patch

oauth2_provider/oauth2_backends.py#L246-L251

Added lines #L246 - L251 were not covered by tests

return res

Check warning on line 253 in oauth2_provider/oauth2_backends.py

View check run for this annotation

Codecov / codecov/patch

oauth2_provider/oauth2_backends.py#L253

Added line #L253 was not covered by tests

return super(OAuthLibCoreFixed, self).extract_body(request)

Check warning on line 255 in oauth2_provider/oauth2_backends.py

View check run for this annotation

Codecov / codecov/patch

oauth2_provider/oauth2_backends.py#L255

Added line #L255 was not covered by tests


def get_oauthlib_core():
"""
Utility function that returns an instance of
Expand Down
Loading