fast-auth-tools


Namefast-auth-tools JSON
Version 0.2.1 PyPI version JSON
download
home_pagehttps://github.com/nihilok/auth_base
SummarySimple Authentication Library for FastAPI
upload_time2023-09-24 23:01:37
maintainer
docs_urlNone
authornihilok
requires_python
license
keywords
VCS
bugtrack_url
requirements aiosqlite fastapi pydantic passlib starlette bcrypt python-jose python-multipart
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Fast Auth Tools (for FastAPI)

> Add authentication to a FastApi app with a single function

### Install
```shell
pip install fast-auth-tools
```

### Create User DB

```shell
python -m fast_auth.create_sqlite_db ./my_user_db.sqlite3
```
_db path argument is optional and will default to .../site_packages/fast_auth/users.sqlite3_

### Example

```python
import os

from fastapi import FastAPI, Depends

from fast_auth import fast_auth, logged_in_user, User
from fast_auth import settings as auth_settings

auth_settings.user_db_path = "./my_user_db.sqlite3" # if the path was changed
auth_settings.secret_key = os.getenv("FAST_AUTH_SECRET_KEY")
auth_settings.cors_origins = ["myapp.com", "my-test-server.com"]

app = FastAPI()
fast_auth(app)

@app.get("/secure/get/", dependencies=[Depends(logged_in_user)])
async def must_be_logged_in():
    return {}

@app.post("/secure/post/")
async def get_user_object(user: User = Depends(logged_in_user)):
    print(f"password hash: {user.password}")
    return {
        "data": f"{user.username} is already logged in"
    }
```

### Settings

| name                     | default                                     | description                                                                           |
|--------------------------|---------------------------------------------|---------------------------------------------------------------------------------------|
| cors_origins             | \["*"]                                      | allowed CORS origins                                                                  |
| secret_key               | "SoMeThInG_-sUp3Rs3kREt!!"                  | the key used to encrypt JWT                                                           |
| algorithm                | "HS256"                                     | the alogrithm used to encrypt JWT                                                     |
| access_token_expire_days | 5                                           | the maximum number of days JWT will be valid                                          |
| user_db_path             | ".../site_packages/fast_auth/users.sqlite3" | the path to the sqlite database that holds username/encrypted password information    |
| login_url                | "login"                                     | path to POST endpoint accepting username/password form data                           |
| token_refresh_url        | "refresh_token"                              | path to GET endpoint that takes a valid JWT and returns a new JWT with maximum expiry |

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/nihilok/auth_base",
    "name": "fast-auth-tools",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "nihilok",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/8d/f6/5dcda4a814c19d6a8a44ece641b3005375bc38bc8486bcde0645f2884795/fast-auth-tools-0.2.1.tar.gz",
    "platform": null,
    "description": "# Fast Auth Tools (for FastAPI)\n\n> Add authentication to a FastApi app with a single function\n\n### Install\n```shell\npip install fast-auth-tools\n```\n\n### Create User DB\n\n```shell\npython -m fast_auth.create_sqlite_db ./my_user_db.sqlite3\n```\n_db path argument is optional and will default to .../site_packages/fast_auth/users.sqlite3_\n\n### Example\n\n```python\nimport os\n\nfrom fastapi import FastAPI, Depends\n\nfrom fast_auth import fast_auth, logged_in_user, User\nfrom fast_auth import settings as auth_settings\n\nauth_settings.user_db_path = \"./my_user_db.sqlite3\" # if the path was changed\nauth_settings.secret_key = os.getenv(\"FAST_AUTH_SECRET_KEY\")\nauth_settings.cors_origins = [\"myapp.com\", \"my-test-server.com\"]\n\napp = FastAPI()\nfast_auth(app)\n\n@app.get(\"/secure/get/\", dependencies=[Depends(logged_in_user)])\nasync def must_be_logged_in():\n    return {}\n\n@app.post(\"/secure/post/\")\nasync def get_user_object(user: User = Depends(logged_in_user)):\n    print(f\"password hash: {user.password}\")\n    return {\n        \"data\": f\"{user.username} is already logged in\"\n    }\n```\n\n### Settings\n\n| name                     | default                                     | description                                                                           |\n|--------------------------|---------------------------------------------|---------------------------------------------------------------------------------------|\n| cors_origins             | \\[\"*\"]                                      | allowed CORS origins                                                                  |\n| secret_key               | \"SoMeThInG_-sUp3Rs3kREt!!\"                  | the key used to encrypt JWT                                                           |\n| algorithm                | \"HS256\"                                     | the alogrithm used to encrypt JWT                                                     |\n| access_token_expire_days | 5                                           | the maximum number of days JWT will be valid                                          |\n| user_db_path             | \".../site_packages/fast_auth/users.sqlite3\" | the path to the sqlite database that holds username/encrypted password information    |\n| login_url                | \"login\"                                     | path to POST endpoint accepting username/password form data                           |\n| token_refresh_url        | \"refresh_token\"                              | path to GET endpoint that takes a valid JWT and returns a new JWT with maximum expiry |\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Simple Authentication Library for FastAPI",
    "version": "0.2.1",
    "project_urls": {
        "Homepage": "https://github.com/nihilok/auth_base"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8df65dcda4a814c19d6a8a44ece641b3005375bc38bc8486bcde0645f2884795",
                "md5": "b94e97592d9a4400c54dcf78e8ce9f95",
                "sha256": "0262ec0de356ae06b630fd193dcab75e5ed5a263a57e16fea5ca2a3c774a3fb9"
            },
            "downloads": -1,
            "filename": "fast-auth-tools-0.2.1.tar.gz",
            "has_sig": false,
            "md5_digest": "b94e97592d9a4400c54dcf78e8ce9f95",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6184,
            "upload_time": "2023-09-24T23:01:37",
            "upload_time_iso_8601": "2023-09-24T23:01:37.450444Z",
            "url": "https://files.pythonhosted.org/packages/8d/f6/5dcda4a814c19d6a8a44ece641b3005375bc38bc8486bcde0645f2884795/fast-auth-tools-0.2.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-24 23:01:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "nihilok",
    "github_project": "auth_base",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "aiosqlite",
            "specs": [
                [
                    ">=",
                    "0.18.0"
                ]
            ]
        },
        {
            "name": "fastapi",
            "specs": [
                [
                    ">=",
                    "0.89.0"
                ]
            ]
        },
        {
            "name": "pydantic",
            "specs": [
                [
                    ">=",
                    "1.10.4"
                ]
            ]
        },
        {
            "name": "passlib",
            "specs": [
                [
                    ">=",
                    "1.7.4"
                ]
            ]
        },
        {
            "name": "starlette",
            "specs": [
                [
                    ">=",
                    "0.22.0"
                ]
            ]
        },
        {
            "name": "bcrypt",
            "specs": [
                [
                    ">=",
                    "4.0.1"
                ]
            ]
        },
        {
            "name": "python-jose",
            "specs": [
                [
                    ">=",
                    "3.3.0"
                ]
            ]
        },
        {
            "name": "python-multipart",
            "specs": [
                [
                    ">=",
                    "0.0.5"
                ]
            ]
        }
    ],
    "lcname": "fast-auth-tools"
}
        
Elapsed time: 0.23533s