Skip to content

Fixed Form UrlEncoded OAuth Lib Core #1382

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

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 @@ def extract_body(self, request):
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']:
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"])
res = query_params.items()

return res

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


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