Skip to content

Updated README.rst with example authentication flow #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -71,3 +71,18 @@ you can use the ``COGNITO_USER_MODEL`` setting.
.. code-block:: python

COGNITO_USER_MODEL = "myproject.AppUser"


Example authentication flow
===========================
1) Client sends username and password to DRF using a POST request.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What endpoint you are talking about?
I don't understand

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

django-cognito-jwt doesn't handle logging in. Any user needs to be logged in with cognito separately. So as an example, I create an APIview which takes a username and password through POST, and use boto3 to authenticate the credentials and receive the tokens.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What to do next? the tokens not get authenticated by using the authentication_classes=[JSONWebTokenAuthentication]

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honest, I haven't worked with this in more than 4 years. I am not even sure what this all about. Sorry about that.


2) DRF authenticates it with AWS Cognito using ``AdminInitiateAuth`` (`boto3 <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp.html#CognitoIdentityProvider.Client.admin_initiate_auth>`_) and sends the tokens recived from AWS Congnito back to the client.

3) Client sends request (with the recived ``IdToken`` set as the authentication header) to the API which uses ``django_cognito_jwt.JSONWebTokenAuthentication`` as the ``authentication_classes``

.. code-block:: python
header = {'Authorization': 'token {}'.format(authentication_result['IdToken'])}
response = requests.post("http://127.0.0.1:8000/<API with authentication>/", headers=header)

Note: the `get_or_create_for_cognito` method of the User model needs to be implementated. (refer to: `#11 <https://github.com/labd/django-cognito-jwt/issues/3>`_