i18n
This commit is contained in:
parent
b763d5ad4e
commit
97b8dfdc21
7 changed files with 90 additions and 6 deletions
|
|
@ -3,15 +3,17 @@ from django.urls import re_path, path
|
|||
from oauth2_provider import views
|
||||
from rest_framework import routers
|
||||
|
||||
from .views.introspect import IntrospectTokenView, IntrospectApplicationView
|
||||
from .views.introspect import IntrospectTokenView, IntrospectApplicationView, TokenView
|
||||
from .views import apis as api_views
|
||||
from .views import pages
|
||||
app_name = "gooyal_oauth2"
|
||||
|
||||
|
||||
|
||||
|
||||
base_urlpatterns = [
|
||||
re_path(r"^authorize/$", views.AuthorizationView.as_view(), name="authorize"),
|
||||
re_path(r"^token/$", views.TokenView.as_view(), name="token"),
|
||||
re_path(r"^token/$", TokenView.as_view(), name="token"),
|
||||
re_path(r"^revoke_token/$", views.RevokeTokenView.as_view(), name="revoke-token"),
|
||||
re_path(r"^introspect/$", IntrospectTokenView.as_view(), name="introspect"),
|
||||
re_path(r"^introspect_application/$", IntrospectApplicationView.as_view(), name="introspect-application"),
|
||||
|
|
|
|||
|
|
@ -1,12 +1,16 @@
|
|||
import calendar
|
||||
|
||||
from allauth.account.internal.decorators import login_not_required
|
||||
from django.core.exceptions import ObjectDoesNotExist
|
||||
from django.http import JsonResponse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
from oauth2_provider.models import get_access_token_model, get_application_model
|
||||
from oauth2_provider.signals import app_authorized
|
||||
from oauth2_provider.views.generic import ClientProtectedScopedResourceView
|
||||
from oauth2_provider.views.mixins import OAuthLibMixin
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name="dispatch")
|
||||
|
|
@ -117,3 +121,49 @@ class IntrospectApplicationView(ClientProtectedScopedResourceView):
|
|||
:return:
|
||||
"""
|
||||
return self.get_application_response(request.POST.get("client_id", None))
|
||||
|
||||
|
||||
|
||||
import hashlib
|
||||
import json
|
||||
from django.http import HttpResponse
|
||||
from django.utils.decorators import method_decorator
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from django.views.decorators.debug import sensitive_post_parameters
|
||||
from django.views.generic import FormView, View
|
||||
|
||||
|
||||
@method_decorator(csrf_exempt, name="dispatch")
|
||||
@method_decorator(login_not_required, name="dispatch")
|
||||
class TokenView(OAuthLibMixin, View):
|
||||
"""
|
||||
Implements an endpoint to provide access tokens
|
||||
|
||||
The endpoint is used in the following flows:
|
||||
* Authorization code
|
||||
* Password
|
||||
* Client credentials
|
||||
"""
|
||||
|
||||
@method_decorator(sensitive_post_parameters("password", "client_secret"))
|
||||
def post(self, request, *args, **kwargs):
|
||||
url, headers, body, status = self.create_token_response(request)
|
||||
content = json.loads(body)
|
||||
for k,v in content.items():
|
||||
_('Invalid credentials given.')
|
||||
_('invalid_grant')
|
||||
|
||||
content[k] = _(v)
|
||||
|
||||
if status == 200:
|
||||
access_token = json.loads(body).get("access_token")
|
||||
if access_token is not None:
|
||||
token_checksum = hashlib.sha256(access_token.encode("utf-8")).hexdigest()
|
||||
token = get_access_token_model().objects.get(token_checksum=token_checksum)
|
||||
app_authorized.send(sender=self, request=request, token=token)
|
||||
response = HttpResponse(content=body, status=status)
|
||||
|
||||
for k, v in headers.items():
|
||||
response[k] = v
|
||||
return response
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-02-03 10:16+0000\n"
|
||||
"POT-Creation-Date: 2026-02-03 10:43+0000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
|
@ -35,6 +35,14 @@ msgstr ""
|
|||
msgid "Turkish"
|
||||
msgstr ""
|
||||
|
||||
#: apps/gooyal_oauth2/views/introspect.py:153
|
||||
msgid "Invalid credentials given."
|
||||
msgstr ""
|
||||
|
||||
#: apps/gooyal_oauth2/views/introspect.py:154
|
||||
msgid "invalid_grant"
|
||||
msgstr ""
|
||||
|
||||
#: apps/users/constans.py:9
|
||||
msgid "male"
|
||||
msgstr ""
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-02-03 10:16+0000\n"
|
||||
"POT-Creation-Date: 2026-02-03 10:43+0000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
|
@ -34,6 +34,14 @@ msgstr ""
|
|||
msgid "Turkish"
|
||||
msgstr ""
|
||||
|
||||
#: apps/gooyal_oauth2/views/introspect.py:153
|
||||
msgid "Invalid credentials given."
|
||||
msgstr ""
|
||||
|
||||
#: apps/gooyal_oauth2/views/introspect.py:154
|
||||
msgid "invalid_grant"
|
||||
msgstr ""
|
||||
|
||||
#: apps/users/constans.py:9
|
||||
msgid "male"
|
||||
msgstr ""
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-02-03 10:16+0000\n"
|
||||
"POT-Creation-Date: 2026-02-03 10:43+0000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
|
@ -34,6 +34,14 @@ msgstr ""
|
|||
msgid "Turkish"
|
||||
msgstr ""
|
||||
|
||||
#: apps/gooyal_oauth2/views/introspect.py:153
|
||||
msgid "Invalid credentials given."
|
||||
msgstr "اطلاعات وارد شده برای اعتبار سنجی نادرست است."
|
||||
|
||||
#: apps/gooyal_oauth2/views/introspect.py:154
|
||||
msgid "invalid_grant"
|
||||
msgstr "دسترسی اشتباه"
|
||||
|
||||
#: apps/users/constans.py:9
|
||||
msgid "male"
|
||||
msgstr ""
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"Report-Msgid-Bugs-To: \n"
|
||||
"POT-Creation-Date: 2026-02-03 10:16+0000\n"
|
||||
"POT-Creation-Date: 2026-02-03 10:43+0000\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
|
@ -34,6 +34,14 @@ msgstr ""
|
|||
msgid "Turkish"
|
||||
msgstr ""
|
||||
|
||||
#: apps/gooyal_oauth2/views/introspect.py:153
|
||||
msgid "Invalid credentials given."
|
||||
msgstr ""
|
||||
|
||||
#: apps/gooyal_oauth2/views/introspect.py:154
|
||||
msgid "invalid_grant"
|
||||
msgstr ""
|
||||
|
||||
#: apps/users/constans.py:9
|
||||
msgid "male"
|
||||
msgstr ""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue