Metadata-Version: 2.1
Name: django-appwrite
Version: 1.2.1
Summary: Django Middleware to authenticate users with Appwrite
Home-page: https://github.com/khashashin/django-appwrite
Author: Yusup Khasbulatov
License: MIT
Project-URL: Documentation, https://github.com/khashashin/django-appwrite/blob/main/README.md
Project-URL: Funding, https://donate.pypi.org
Project-URL: Say Thanks!, https://patreon.com/khashashin
Project-URL: Source, https://github.com/khashashin/django-appwrite
Project-URL: Tracker, https://github.com/khashashin/django-appwrite/issues
Keywords: appwrite auth django
Classifier: Framework :: Django
Classifier: Topic :: Utilities
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Description-Content-Type: text/markdown
License-File: LICENSE

# Appwrite Middleware for Django

![PyPI version](https://badge.fury.io/py/django-appwrite.svg)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/django-appwrite)
![PyPI - License](https://img.shields.io/pypi/l/django-appwrite)

A Django middleware to authenticate users with Appwrite.

## Installation

To install `django_appwrite`, simply run:

```bash
$ pip install django-appwrite
```

## Usage
1. Add `django_appwrite` to your INSTALLED_APPS list in your Django project's `settings.py` file:

```python
INSTALLED_APPS = [
    ...,
    'django_appwrite',
    ...
]
```

2. Add `django_appwrite.middleware.AppwriteMiddleware` to your MIDDLEWARE list in your Django project's `settings.py` file. It should be placed after the `AuthenticationMiddleware`:

```python
MIDDLEWARE = [
    ...,
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django_appwrite.middleware.AppwriteMiddleware',
    ...
]
```
3. Configure the Appwrite client settings in your Django settings file:
```python
APPWRITE = {
    'PROJECT_ENDPOINT': 'https://example.com/v1',
    'PROJECT_ID': 'PROJECT_ID',
    'PROJECT_API_KEY': 'PROJECT_API_KEY',
}
```
| Setting            | Default      | Description                                                                                                                                                                                                           |
|--------------------|--------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `PROJECT_ENDPOINT` |              | The endpoint of your Appwrite project. You can find this in the Appwrite console under Settings > General.                                                                                                            |
| `PROJECT_ID`       |              | The ID of your Appwrite project. You can find this in the Appwrite console under Settings > General.                                                                                                                  |
| `PROJECT_API_KEY`  |              | The API key of your Appwrite project. You can find this in the Appwrite console under Settings > API Keys.                                                                                                            |
| `USER_ID_HEADER`   | HTTP_USER_ID | The header name that will be used to store the user ID.                                                                                                                                                               |
| `VERIFY_EMAIL`     | False        | If set to `True`, the middleware will check if the user's email address has been verified in Appwrite before authenticating the user. If the email address has not been verified, the user will not be authenticated. |
| `VERIFY_PHONE`     | False        | If set to `True`, the middleware will check if the user's phone number has been verified in Appwrite before authenticating the user. If the phone number has not been verified, the user will not be authenticated.   |

## How it works
This middleware class will get the user ID from the header specified in the `USER_ID_HEADER` setting.
It will then use this user ID to retrieve the user information from Appwrite using the `Users` service.
If a user is found, it will create a Django user if it doesn't exist, and authenticate the user.

Please note that this middleware is intended to be used in conjunction with the Appwrite client-side SDK to authorize users on the frontend, and does not provide any APIs for user authentication on its own.

## License
The appwrite-drf package is released under the MIT License. See the bundled [LICENSE](LICENSE) file for details.
