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 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
18 changes: 17 additions & 1 deletion oauth2_provider/oauth2_backends.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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 +238,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 ["application/x-www-form-urlencoded"]:
try:
query_string = request.body.decode("utf-8")
query_params = {p.split("=")[0]: unquote(p.split("=")[1]) for p in query_string.split("&")}
res = query_params.items()

Check warning on line 248 in oauth2_provider/oauth2_backends.py

View check run for this annotation

Codecov / codecov/patch

oauth2_provider/oauth2_backends.py#L244-L248

Added lines #L244 - L248 were not covered by tests

return res
except:
pass

Check warning on line 252 in oauth2_provider/oauth2_backends.py

View check run for this annotation

Codecov / codecov/patch

oauth2_provider/oauth2_backends.py#L250-L252

Added lines #L250 - L252 were not covered by tests

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

Check warning on line 254 in oauth2_provider/oauth2_backends.py

View check run for this annotation

Codecov / codecov/patch

oauth2_provider/oauth2_backends.py#L254

Added line #L254 was not covered by tests


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