Skip to content

Commit c46fcb0

Browse files
committed
Add doc on cookies authentication
1 parent b9a791a commit c46fcb0

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

docs/transports/aiohttp.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,39 @@ This transport uses the `aiohttp`_ library and allows you to send GraphQL querie
1212

1313
.. literalinclude:: ../code_examples/aiohttp_async.py
1414

15+
Authentication
16+
--------------
17+
18+
There are multiple ways to authenticate depending on the server configuration.
19+
20+
1. Using HTTP Headers
21+
22+
.. code-block:: python
23+
24+
transport = AIOHTTPTransport(
25+
url='https://SERVER_URL:SERVER_PORT/graphql',
26+
headers={'Authorization': 'token'}
27+
)
28+
29+
2. Using HTTP Cookies
30+
31+
You can manually set the cookies which will be sent with each connection:
32+
33+
.. code-block:: python
34+
35+
transport = AIOHTTPTransport(url=url, cookies={"cookie1": "val1"})
36+
37+
Or you can use a cookie jar to save cookies set from the backend and reuse them later.
38+
39+
In some cases, the server will set some connection cookies after a successful login mutation
40+
and you can save these cookies in a cookie jar to reuse them in a following connection
41+
(See `issue 197`_):
42+
43+
.. code-block:: python
44+
45+
jar = aiohttp.CookieJar()
46+
transport = AIOHTTPTransport(url=url, client_session_args={'cookie_jar': jar})
47+
48+
1549
.. _aiohttp: https://docs.aiohttp.org
50+
.. _issue 197: https://github.com/graphql-python/gql/issues/197

0 commit comments

Comments
 (0)