Коммит 430e05ae создал по автору paragliding@ngs.ru's avatar paragliding@ngs.ru
Просмотр файлов

token_no_refresh

владелец bc5f1391
Нет предварительного просмотра для этого типа файлов
# import graphene
# import graphql_jwt
# class Mutation(graphene.ObjectType):
# token_auth = graphql_jwt.ObtainJSONWebToken.Field()
# verify_token = graphql_jwt.Verify.Field()
# refresh_token = graphql_jwt.Refresh.Field()
# schema = graphene.Schema(mutation=Mutation)
import graphene
import graphql_jwt
from wagtail.api.v2.views import PagesAPIViewSet
from wagtail.api.v2.router import WagtailAPIRouter
from wagtail.api.v2.utils import BadRequestError
from wagtail.models import Page
from wagtail.users.models import UserProfile
from graphene_django import DjangoObjectType
class UserType(DjangoObjectType):
class Meta:
model = UserProfile
fields = "__all__"
class PageType(DjangoObjectType):
class Meta:
model = Page
fields = "__all__"
class ObtainJSONWebToken(graphql_jwt.JSONWebTokenMutation):
user = graphene.Field(UserType)
@classmethod
def resolve(cls, root, info, **kwargs):
return cls(user=info.context.user)
# class RefreshMutation(graphql_jwt.RefreshMutation):
# user = graphene.Field(UserType)
# @classmethod
# def resolve(cls, root, info, **kwargs):
# return cls(user=info.context.user)
# class RevokeMutation(graphql_jwt.RevokeMutation):
# user = graphene.Field(UserType)
# @classmethod
# def resolve(cls, root, info, **kwargs):
# return cls(user=info.context.user)
class Mutation(graphene.ObjectType):
token_auth = ObtainJSONWebToken.Field()
verify_token = graphql_jwt.Verify.Field()
# refresh_token = RefreshMutation.Field()
# revoke_token = RevokeMutation.Field()
router = WagtailAPIRouter('wagtailapi')
router.register_endpoint('pages', PagesAPIViewSet)
class Query(graphene.ObjectType):
pages = graphene.List(PageType)
def resolve_pages(self, info):
return Page.objects.live().public()
schema = graphene.Schema(query=Query, mutation=Mutation)
......@@ -26,6 +26,7 @@ BASE_DIR = os.path.dirname(PROJECT_DIR)
INSTALLED_APPS = [
"home",
"search",
'wagtail.api.v2',
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.embeds",
......@@ -45,6 +46,11 @@ INSTALLED_APPS = [
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"grapple",
"graphene_django",
'graphql_jwt',
]
MIDDLEWARE = [
......@@ -56,6 +62,7 @@ MIDDLEWARE = [
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.middleware.security.SecurityMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
# "graphql_jwt.middleware.JSONWebTokenMiddleware",
]
ROOT_URLCONF = "myproject.urls"
......@@ -114,7 +121,7 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/4.2/topics/i18n/
LANGUAGE_CODE = "en-us"
LANGUAGE_CODE = "ru-ru"
TIME_ZONE = "UTC"
......@@ -164,3 +171,54 @@ WAGTAILSEARCH_BACKENDS = {
# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
WAGTAILADMIN_BASE_URL = "http://example.com"
AUTHENTICATION_BACKENDS = [
"graphql_jwt.backends.JSONWebTokenBackend",
"django.contrib.auth.backends.ModelBackend",
]
# Grapple Config:
# GRAPHENE = {"SCHEMA": "grapple.schema.schema"}
GRAPHENE = {
# "SCHEMA": "grapple.schema.schema",
"SCHEMA": "myproject.schema.schema",
# "MIDDLEWARE": [
# "graphql_jwt.middleware.JSONWebTokenMiddleware",
# ],}
'MIDDLEWARE': [
'graphql_jwt.middleware.JSONWebTokenMiddleware',
],
'DEFAULT_FIELD_FORMAT': 'grapple.types.fields.GrappleField',
'RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST': True,
'RELAY_CONNECTION_MAX_LIMIT': 100,
'RELAY_CONNECTION_ENFORCE_MAX_LIMIT': True,
}
GRAPPLE = {
"APPS": ["home"],
"ADD_SEARCH_HIT": True,
"EXPOSE_GRAPHIQL": True,
}
GRAPHQL_JWT = {
'JWT_ALLOW_ARGUMENT': True,
'JWT_VERIFY': True,
'JWT_VERIFY_EXPIRATION': True,
# 'JWT_EXPIRATION_DELTA': timedelta(minutes=5),
# 'JWT_REFRESH_EXPIRATION_DELTA': timedelta(days=7),
'JWT_AUTH_HEADER_PREFIX': 'Bearer',
'JWT_REFRESH_TOKEN_COOKIE_NAME': 'refresh_token',
'JWT_LONG_RUNNING_REFRESH_TOKEN': True,
'JWT_ALLOW_ANY_CLASSES': [
'graphql_auth.mutations.Register',
'graphql_auth.mutations.VerifyAccount',
'graphql_auth.mutations.ResendActivationEmail',
'graphql_auth.mutations.SendPasswordResetEmail',
'graphql_auth.mutations.PasswordReset',
'graphql_auth.mutations.ObtainJSONWebToken',
'graphql_auth.mutations.VerifyToken',
'graphql_auth.mutations.RefreshToken',
'graphql_auth.mutations.RevokeToken',
],
}
......@@ -8,11 +8,18 @@ from wagtail.documents import urls as wagtaildocs_urls
from search import views as search_views
from grapple import urls as grapple_urls
from graphene_django.views import GraphQLView
from graphql_jwt.decorators import jwt_cookie
urlpatterns = [
path("django-admin/", admin.site.urls),
path("admin/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
path("search/", search_views.search, name="search"),
path("", include(grapple_urls)),
path("graphql/", jwt_cookie(GraphQLView.as_view())),
]
......
wagtail-grapple @ a4035420
Subproject commit a40354200a5977bb792cad73d8f667e297666eae
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать