fastapi-key-auth


Namefastapi-key-auth JSON
Version 0.15.3 PyPI version JSON
download
home_pagehttps://github.com/iwpnd/fastapi-key-auth
SummaryAPI key validation Middleware
upload_time2024-05-05 08:02:07
maintainerNone
docs_urlNone
authorBenjamin Ramser
requires_python<4.0,>=3.9
licenseMIT
keywords fastapi api key security
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <br />
<p align="center">
  <h3 align="center">FastAPI-key-auth</h3>

  <p align="center">
    Secure your FastAPI endpoints using API keys.
    <br />
    <a href="https://github.com/iwpnd/fastapi-key-auth/issues">Report Bug</a>
    ยท
    <a href="https://github.com/iwpnd/fastapi-key-auth/issues">Request Feature</a>
  </p>
</p>

<!-- TABLE OF CONTENTS -->
<details open="open">
  <summary><h2 style="display: inline-block">Table of Contents</h2></summary>
  <ol>
    <li>
      <a href="#about-the-project">About The Project</a>
      <ul>
        <li><a href="#built-with">Built With</a></li>
      </ul>
    </li>
    <li>
      <a href="#getting-started">Getting Started</a>
      <ul>
        <li><a href="#installation">Installation</a></li>
      </ul>
    </li>
    <li><a href="#usage">Usage</a></li>
    <li><a href="#license">License</a></li>
    <li><a href="#contact">Contact</a></li>
  </ol>
</details>

<!-- ABOUT THE PROJECT -->

## About The Project

On deployment inject API keys authorized to use your service. Every call to a private
endpoint of your service has to include a `header['x-api-key']` attribute that is
validated against the API keys in your environment.
If it is present, a request is authorized. If it is not FastAPI return `401 Unauthorized`.
Use this either as a middleware, or as Dependency.

### Built With

-   [starlette](https://github.com/encode/starlette)
-   [fastapi](https://github.com/tiangolo/fastapi)

<!-- GETTING STARTED -->

## Getting Started

### Installation

1. Clone and install
    ```sh
    git clone https://github.com/iwpnd/fastapi-key-auth.git
    poetry install
    ```
2. Install with pip
    ```sh
    pip install fastapi-key-auth
    ```
3. Install with poetry
    ```sh
    poetry add fastapi-key-auth
    ```

## Usage

As Middleware:

```python
from fastapi import FastAPI
from fastapi_key_auth import AuthorizerMiddleware

app = FastAPI()

app.add_middleware(AuthorizerMiddleware, public_paths=["/ping"], key_pattern="API_KEY_")

# optional use regex startswith
app.add_middleware(AuthorizerMiddleware, public_paths=["/ping", "^/users"])
```

As Dependency

```python
from fastapi import FastAPI, Depends
from fastapi_key_auth import AuthorizerDependency

authorizer = AuthorizerDependency(key_pattern="API_KEY_")

# either globally or in a router
app = FastAPI(dependencies=[Depends(authorizer)])
```

## License

Distributed under the MIT License. See `LICENSE` for more information.

<!-- CONTACT -->

## Contact

Benjamin Ramser - [@imwithpanda](https://twitter.com/imwithpanda) - ahoi@iwpnd.pw  
Project Link: [https://github.com/iwpnd/fastapi-key-auth](https://github.com/iwpnd/fastapi-key-auth)


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/iwpnd/fastapi-key-auth",
    "name": "fastapi-key-auth",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "fastapi, api key, security",
    "author": "Benjamin Ramser",
    "author_email": "legionaerr@googlemail.com",
    "download_url": "https://files.pythonhosted.org/packages/93/b7/54465b0c3f5b856593489bc6685a14909fc24d64710e248b9ebbb7570e94/fastapi_key_auth-0.15.3.tar.gz",
    "platform": null,
    "description": "<br />\n<p align=\"center\">\n  <h3 align=\"center\">FastAPI-key-auth</h3>\n\n  <p align=\"center\">\n    Secure your FastAPI endpoints using API keys.\n    <br />\n    <a href=\"https://github.com/iwpnd/fastapi-key-auth/issues\">Report Bug</a>\n    \u00b7\n    <a href=\"https://github.com/iwpnd/fastapi-key-auth/issues\">Request Feature</a>\n  </p>\n</p>\n\n<!-- TABLE OF CONTENTS -->\n<details open=\"open\">\n  <summary><h2 style=\"display: inline-block\">Table of Contents</h2></summary>\n  <ol>\n    <li>\n      <a href=\"#about-the-project\">About The Project</a>\n      <ul>\n        <li><a href=\"#built-with\">Built With</a></li>\n      </ul>\n    </li>\n    <li>\n      <a href=\"#getting-started\">Getting Started</a>\n      <ul>\n        <li><a href=\"#installation\">Installation</a></li>\n      </ul>\n    </li>\n    <li><a href=\"#usage\">Usage</a></li>\n    <li><a href=\"#license\">License</a></li>\n    <li><a href=\"#contact\">Contact</a></li>\n  </ol>\n</details>\n\n<!-- ABOUT THE PROJECT -->\n\n## About The Project\n\nOn deployment inject API keys authorized to use your service. Every call to a private\nendpoint of your service has to include a `header['x-api-key']` attribute that is\nvalidated against the API keys in your environment.\nIf it is present, a request is authorized. If it is not FastAPI return `401 Unauthorized`.\nUse this either as a middleware, or as Dependency.\n\n### Built With\n\n-   [starlette](https://github.com/encode/starlette)\n-   [fastapi](https://github.com/tiangolo/fastapi)\n\n<!-- GETTING STARTED -->\n\n## Getting Started\n\n### Installation\n\n1. Clone and install\n    ```sh\n    git clone https://github.com/iwpnd/fastapi-key-auth.git\n    poetry install\n    ```\n2. Install with pip\n    ```sh\n    pip install fastapi-key-auth\n    ```\n3. Install with poetry\n    ```sh\n    poetry add fastapi-key-auth\n    ```\n\n## Usage\n\nAs Middleware:\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_key_auth import AuthorizerMiddleware\n\napp = FastAPI()\n\napp.add_middleware(AuthorizerMiddleware, public_paths=[\"/ping\"], key_pattern=\"API_KEY_\")\n\n# optional use regex startswith\napp.add_middleware(AuthorizerMiddleware, public_paths=[\"/ping\", \"^/users\"])\n```\n\nAs Dependency\n\n```python\nfrom fastapi import FastAPI, Depends\nfrom fastapi_key_auth import AuthorizerDependency\n\nauthorizer = AuthorizerDependency(key_pattern=\"API_KEY_\")\n\n# either globally or in a router\napp = FastAPI(dependencies=[Depends(authorizer)])\n```\n\n## License\n\nDistributed under the MIT License. See `LICENSE` for more information.\n\n<!-- CONTACT -->\n\n## Contact\n\nBenjamin Ramser - [@imwithpanda](https://twitter.com/imwithpanda) - ahoi@iwpnd.pw  \nProject Link: [https://github.com/iwpnd/fastapi-key-auth](https://github.com/iwpnd/fastapi-key-auth)\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "API key validation Middleware",
    "version": "0.15.3",
    "project_urls": {
        "Homepage": "https://github.com/iwpnd/fastapi-key-auth",
        "Repository": "https://github.com/iwpnd/fastapi-key-auth"
    },
    "split_keywords": [
        "fastapi",
        " api key",
        " security"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7f80f9a9701c82691df2f86218b1b8fe006c8a77dc6e33df6ab1fefce43058de",
                "md5": "25994f3532e369403c693995dc8f9f6a",
                "sha256": "5dfc54cadaf384235d1c6a0376a7dceb1f3d877e0886e0592b004f16ef9cd2c6"
            },
            "downloads": -1,
            "filename": "fastapi_key_auth-0.15.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "25994f3532e369403c693995dc8f9f6a",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 5560,
            "upload_time": "2024-05-05T08:02:05",
            "upload_time_iso_8601": "2024-05-05T08:02:05.911536Z",
            "url": "https://files.pythonhosted.org/packages/7f/80/f9a9701c82691df2f86218b1b8fe006c8a77dc6e33df6ab1fefce43058de/fastapi_key_auth-0.15.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "93b754465b0c3f5b856593489bc6685a14909fc24d64710e248b9ebbb7570e94",
                "md5": "3321626b5b760de7a3e580125a7d3eed",
                "sha256": "c6c79f1b49f87cdf1f49d1d6816f70c0c0d50942cd03bfff57890055d142b296"
            },
            "downloads": -1,
            "filename": "fastapi_key_auth-0.15.3.tar.gz",
            "has_sig": false,
            "md5_digest": "3321626b5b760de7a3e580125a7d3eed",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 4595,
            "upload_time": "2024-05-05T08:02:07",
            "upload_time_iso_8601": "2024-05-05T08:02:07.543895Z",
            "url": "https://files.pythonhosted.org/packages/93/b7/54465b0c3f5b856593489bc6685a14909fc24d64710e248b9ebbb7570e94/fastapi_key_auth-0.15.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-05 08:02:07",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "iwpnd",
    "github_project": "fastapi-key-auth",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "fastapi-key-auth"
}
        
Elapsed time: 0.26828s