fastapi-key-auth


Namefastapi-key-auth JSON
Version 0.15.4 PyPI version JSON
download
home_pagehttps://github.com/iwpnd/fastapi-key-auth
SummaryAPI key validation Middleware
upload_time2024-08-15 12:26:37
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/e3/b2/5e3ff99886e97f2a5e03ba3820b7c1a58eb8f6a3916bedfa7c0b0845e63c/fastapi_key_auth-0.15.4.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.4",
    "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": "c9a6c622a09699e4b39a9f95aa6a1a99fb30be428afee2be59b5b2da4554afe3",
                "md5": "06365b62cbd79f7b0b1173220cb2d7ef",
                "sha256": "94c6ca4310389fc71073cd176d735a95295b54e878f9239699ac5d5ce48b0fa5"
            },
            "downloads": -1,
            "filename": "fastapi_key_auth-0.15.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "06365b62cbd79f7b0b1173220cb2d7ef",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 5556,
            "upload_time": "2024-08-15T12:26:36",
            "upload_time_iso_8601": "2024-08-15T12:26:36.432004Z",
            "url": "https://files.pythonhosted.org/packages/c9/a6/c622a09699e4b39a9f95aa6a1a99fb30be428afee2be59b5b2da4554afe3/fastapi_key_auth-0.15.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "e3b25e3ff99886e97f2a5e03ba3820b7c1a58eb8f6a3916bedfa7c0b0845e63c",
                "md5": "913b1b7a722ccbcadb46b87c2c34eecf",
                "sha256": "772ba47706e1c52051f457714ca8978579cce078d257e4e1007d81aebeb1a84c"
            },
            "downloads": -1,
            "filename": "fastapi_key_auth-0.15.4.tar.gz",
            "has_sig": false,
            "md5_digest": "913b1b7a722ccbcadb46b87c2c34eecf",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 4596,
            "upload_time": "2024-08-15T12:26:37",
            "upload_time_iso_8601": "2024-08-15T12:26:37.271388Z",
            "url": "https://files.pythonhosted.org/packages/e3/b2/5e3ff99886e97f2a5e03ba3820b7c1a58eb8f6a3916bedfa7c0b0845e63c/fastapi_key_auth-0.15.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-15 12:26:37",
    "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.55677s