clerk-django


Nameclerk-django JSON
Version 1.0.3 PyPI version JSON
download
home_pageNone
SummaryA package for django rest framework to handle clerk authentication. It includes a auth middleware, permission and a wrapper around all the user related apis.
upload_time2024-05-19 17:34:21
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT License Copyright (c) 2024 Ravi Kumar Singh. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords django clerk clerk django clerk django package integrate clerk and django
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Clerk Django

"Clerk Django" is a Python library that offers middleware and permissions for authenticating requests when your authentication process is managed by Clerk.

## Installation

Use the package manager [pip](https://pip.pypa.io/en/stable/) to install clerk_django.

```bash
pip install clerk-django
```

## Usage

The first step will be to set your `CLERK_SECRET_KEY` and `CLERK_PEM_PUBLIC_KEY` in your environment variables.
Then go to your `settings.py` file and set the `ALLOWED_PARTIES` config.

```python
ALLOWED_PARTIES = ["http://localhost:5173"]
```

To use the `ClerkAuthMiddleware`, add `clerk_django.middlewares.clerk.ClerkAuthMiddleware` to your middlewares.

```python
MIDDLEWARE = [
    # other middlewares
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'clerk_django.middlewares.clerk.ClerkAuthMiddleware'
]
```

Once you have added the middleware, you can access the user from the request using `request.clerk_user`. clerk_user has 3 properties.

- `is_authenticated` - It is true/false based on if the user is authenticated or not.
- `id` - Clerk user id. This key will be available only if the user is authenticated.
- `decoded_token` - This is the value after decoding the token which might contain useful user info based on how you have configured your [JWTTemplates in Clerk](https://clerk.com/docs/backend-requests/making/jwt-templates). This key will be available only if the user is authenticated.

```python
from rest_framework import viewsets
from rest_framework.response import Response
from permissions.clerk import ClerkAuthenticated

class ExampleViewset(viewsets.ViewSet):
    permission_classes = [ClerkAuthenticated]

    def list(self, request):
        user_id = request.clerk_user.get('id')
        return Response()
```

There is a wrapper around the User related apis. All the different function can be found in [clerk backend sdk](https://clerk.com/docs/references/backend/user/get-user-list) and [ clerk backend apis ](https://clerk.com/docs/reference/backend-api/tag/Users#operation/GetUserList)

```python
from clerk_django.client import ClerkClient

#Set your CLERK_SECRET_KEY and CLERK_PEM_PUBLIC_KEY in your environment variables.

cc = ClerkClient()

user_details = cc.users.getUser(user_id=user_id)

#Check the clerk documentation for the list of query params.
user_list = cc.users.getUserList({
               "email_address" : ["reachsahilverma@gmail.com"]
            })
```

I have added all the functions mentioned in the [Clerk Backend SDK - User](https://clerk.com/docs/references/backend/user/get-user-list). You just need to use `user_id` instead of `userId`. Also in case of `verifyPassword`, just pass the `user_id` and `password` directly. In all the other functions you can pass the params as required and mentioned in the documentation.

```python
res = cc.users.verifyPassword(user_id,password)
```

## Contributing

Pull requests are welcome. For major changes, please open an issue first
to discuss what you would like to change.

## License

[MIT](https://github.com/ravikrsngh/clerk_django?tab=MIT-1-ov-file)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "clerk-django",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "django, clerk, clerk django, clerk django package, integrate clerk and django",
    "author": null,
    "author_email": "Ravi Kumar Singh <ravikrsngh1999@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/33/53/0cfe88f1a1ae9d3cfdbfc09605a20864e66ceeca1f6ff79196d2ec025060/clerk_django-1.0.3.tar.gz",
    "platform": null,
    "description": "# Clerk Django\r\n\r\n\"Clerk Django\" is a Python library that offers middleware and permissions for authenticating requests when your authentication process is managed by Clerk.\r\n\r\n## Installation\r\n\r\nUse the package manager [pip](https://pip.pypa.io/en/stable/) to install clerk_django.\r\n\r\n```bash\r\npip install clerk-django\r\n```\r\n\r\n## Usage\r\n\r\nThe first step will be to set your `CLERK_SECRET_KEY` and `CLERK_PEM_PUBLIC_KEY` in your environment variables.\r\nThen go to your `settings.py` file and set the `ALLOWED_PARTIES` config.\r\n\r\n```python\r\nALLOWED_PARTIES = [\"http://localhost:5173\"]\r\n```\r\n\r\nTo use the `ClerkAuthMiddleware`, add `clerk_django.middlewares.clerk.ClerkAuthMiddleware` to your middlewares.\r\n\r\n```python\r\nMIDDLEWARE = [\r\n    # other middlewares\r\n    'django.contrib.auth.middleware.AuthenticationMiddleware',\r\n    'clerk_django.middlewares.clerk.ClerkAuthMiddleware'\r\n]\r\n```\r\n\r\nOnce you have added the middleware, you can access the user from the request using `request.clerk_user`. clerk_user has 3 properties.\r\n\r\n- `is_authenticated` - It is true/false based on if the user is authenticated or not.\r\n- `id` - Clerk user id. This key will be available only if the user is authenticated.\r\n- `decoded_token` - This is the value after decoding the token which might contain useful user info based on how you have configured your [JWTTemplates in Clerk](https://clerk.com/docs/backend-requests/making/jwt-templates). This key will be available only if the user is authenticated.\r\n\r\n```python\r\nfrom rest_framework import viewsets\r\nfrom rest_framework.response import Response\r\nfrom permissions.clerk import ClerkAuthenticated\r\n\r\nclass ExampleViewset(viewsets.ViewSet):\r\n    permission_classes = [ClerkAuthenticated]\r\n\r\n    def list(self, request):\r\n        user_id = request.clerk_user.get('id')\r\n        return Response()\r\n```\r\n\r\nThere is a wrapper around the User related apis. All the different function can be found in [clerk backend sdk](https://clerk.com/docs/references/backend/user/get-user-list) and [ clerk backend apis ](https://clerk.com/docs/reference/backend-api/tag/Users#operation/GetUserList)\r\n\r\n```python\r\nfrom clerk_django.client import ClerkClient\r\n\r\n#Set your CLERK_SECRET_KEY and CLERK_PEM_PUBLIC_KEY in your environment variables.\r\n\r\ncc = ClerkClient()\r\n\r\nuser_details = cc.users.getUser(user_id=user_id)\r\n\r\n#Check the clerk documentation for the list of query params.\r\nuser_list = cc.users.getUserList({\r\n               \"email_address\" : [\"reachsahilverma@gmail.com\"]\r\n            })\r\n```\r\n\r\nI have added all the functions mentioned in the [Clerk Backend SDK - User](https://clerk.com/docs/references/backend/user/get-user-list). You just need to use `user_id` instead of `userId`. Also in case of `verifyPassword`, just pass the `user_id` and `password` directly. In all the other functions you can pass the params as required and mentioned in the documentation.\r\n\r\n```python\r\nres = cc.users.verifyPassword(user_id,password)\r\n```\r\n\r\n## Contributing\r\n\r\nPull requests are welcome. For major changes, please open an issue first\r\nto discuss what you would like to change.\r\n\r\n## License\r\n\r\n[MIT](https://github.com/ravikrsngh/clerk_django?tab=MIT-1-ov-file)\r\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2024 Ravi Kumar Singh.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "A package for django rest framework to handle clerk authentication. It includes a auth middleware, permission and a wrapper around all the user related apis.",
    "version": "1.0.3",
    "project_urls": {
        "Homepage": "https://github.com/ravikrsngh/clerk_django",
        "Issues": "https://github.com/ravikrsngh/clerk_django/issues"
    },
    "split_keywords": [
        "django",
        " clerk",
        " clerk django",
        " clerk django package",
        " integrate clerk and django"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2a0cbb2d7007c037dc63f5b72333fefb08bfba2ac0bac15acc4822ef2bf1669e",
                "md5": "d4ce9742789ee699cd6f3338cb58826f",
                "sha256": "ea262a364216bfd7125d2485ff4b8a6da3adf97006e622594edb37d3c5e0bf6e"
            },
            "downloads": -1,
            "filename": "clerk_django-1.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d4ce9742789ee699cd6f3338cb58826f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 7311,
            "upload_time": "2024-05-19T17:34:19",
            "upload_time_iso_8601": "2024-05-19T17:34:19.445032Z",
            "url": "https://files.pythonhosted.org/packages/2a/0c/bb2d7007c037dc63f5b72333fefb08bfba2ac0bac15acc4822ef2bf1669e/clerk_django-1.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "33530cfe88f1a1ae9d3cfdbfc09605a20864e66ceeca1f6ff79196d2ec025060",
                "md5": "5f6b3d5ba56fdda61f8dd3d62e149140",
                "sha256": "3be54a3ab66514dfa148b85c0499b098c6f035054d7987f8a460be648aa76b84"
            },
            "downloads": -1,
            "filename": "clerk_django-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "5f6b3d5ba56fdda61f8dd3d62e149140",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 7419,
            "upload_time": "2024-05-19T17:34:21",
            "upload_time_iso_8601": "2024-05-19T17:34:21.288022Z",
            "url": "https://files.pythonhosted.org/packages/33/53/0cfe88f1a1ae9d3cfdbfc09605a20864e66ceeca1f6ff79196d2ec025060/clerk_django-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-19 17:34:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ravikrsngh",
    "github_project": "clerk_django",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "clerk-django"
}
        
Elapsed time: 0.25032s