-
-
Notifications
You must be signed in to change notification settings - Fork 469
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- redesign OAuth2Request - HttpRequest to JsonRequest
- Loading branch information
Showing
16 changed files
with
128 additions
and
177 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from django.http import HttpRequest | ||
from django.utils.functional import cached_property | ||
from authlib.common.encoding import json_loads | ||
from authlib.oauth2.rfc6749 import OAuth2Request, JsonRequest | ||
|
||
|
||
class DjangoOAuth2Request(OAuth2Request): | ||
def __init__(self, request: HttpRequest): | ||
super().__init__(request.method, request.build_absolute_uri(), None, request.headers) | ||
self._request = request | ||
|
||
@property | ||
def args(self): | ||
return self._request.GET | ||
|
||
@property | ||
def form(self): | ||
return self._request.POST | ||
|
||
@cached_property | ||
def data(self): | ||
data = {} | ||
data.update(self._request.GET.dict()) | ||
data.update(self._request.POST.dict()) | ||
return data | ||
|
||
|
||
class DjangoJsonRequest(JsonRequest): | ||
def __init__(self, request: HttpRequest): | ||
super().__init__(request.method, request.build_absolute_uri(), None, request.headers) | ||
self._request = request | ||
|
||
@cached_property | ||
def data(self): | ||
return json_loads(self._request.body) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
from flask.wrappers import Request | ||
from authlib.oauth2.rfc6749 import OAuth2Request, JsonRequest | ||
|
||
|
||
class FlaskOAuth2Request(OAuth2Request): | ||
def __init__(self, request: Request): | ||
super().__init__(request.method, request.url, None, request.headers) | ||
self._request = request | ||
|
||
@property | ||
def args(self): | ||
return self._request.args | ||
|
||
@property | ||
def form(self): | ||
return self._request.form | ||
|
||
@property | ||
def data(self): | ||
return self._request.values | ||
|
||
|
||
class FlaskJsonRequest(JsonRequest): | ||
def __init__(self, request: Request): | ||
super().__init__(request.method, request.url, None, request.headers) | ||
self._request = request | ||
|
||
@property | ||
def data(self): | ||
return self._request.get_json() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.