Skip to content

Commit 441dde4

Browse files
authored
Merge pull request #110 from RadoRado/master
Add `Adding login required` section to authorization
2 parents 5d6c7f2 + b63cb77 commit 441dde4

File tree

1 file changed

+26
-1
lines changed

1 file changed

+26
-1
lines changed

docs/authorization.rst

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Authorization in Django
22
=======================
33

4-
There are two main ways you may want to limit access to data when
4+
There are several ways you may want to limit access to data when
55
working with Graphene and Django: limiting which fields are accessible
66
via GraphQL and limiting which objects a user can access.
77

@@ -108,3 +108,28 @@ method to your ``DjangoObjectType``.
108108
if post.published or context.user == post.owner:
109109
return post
110110
return None
111+
112+
Adding login required
113+
---------------------
114+
115+
If you want to use the standard Django LoginRequiredMixin_ you can create your own view, which includes the ``LoginRequiredMixin`` and subclasses the ``GraphQLView``:
116+
117+
.. code:: python
118+
119+
from django.contrib.auth.mixins import LoginRequiredMixin
120+
from graphene_django.views import GraphQLView
121+
122+
123+
class PrivateGraphQLView(LoginRequiredMixin, GraphQLView):
124+
pass
125+
126+
After this, you can use the new ``PrivateGraphQLView`` in ``urls.py``:
127+
128+
.. code:: python
129+
130+
urlpatterns = [
131+
# some other urls
132+
url(r'^graphql', PrivateGraphQLView.as_view(graphiql=True, schema=schema)),
133+
]
134+
135+
.. _LoginRequiredMixin: https://docs.djangoproject.com/en/1.10/topics/auth/default/#the-loginrequired-mixin

0 commit comments

Comments
 (0)