fastapi-walletauth


Namefastapi-walletauth JSON
Version 1.2.0 PyPI version JSON
download
home_page
SummaryFastAPI extension for user authentication through signature challenges
upload_time2023-10-13 18:21:56
maintainer
docs_urlNone
authormhh
requires_python>=3.8.1,<4.0
license
keywords fastapi authentication signature wallet ethereum solana web3 jwt
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # FastAPI Wallet Authentication

fastapi-walletauth provides a simple way to authenticate users in FastAPI applications using a wallet.
It currently supports Ethereum and Solana wallets/signatures.

## Installation

```shell
pip install fastapi-walletauth
```

## Usage

Adding the authentication endpoints is as simple as importing the `authorization_routes` from `fastapi_walletauth`:

```python
from fastapi import FastAPI
from fastapi_walletauth import authorization_routes

app = FastAPI()

app.include_router(authorization_routes)
```

This will add the following endpoints to your application:

- `POST /authentication/challenge`: Returns a challenge for the user to sign
- `POST /authentication/solve`: Returns a Bearer token if the signature is valid
- `POST /authentication/logout`: Invalidates the current token
- `POST /authentication/refresh`: Returns a new token if the current token is valid

You can then use `WalletAuthDep` to protect your endpoints:

```python
from fastapi import FastAPI
from fastapi_walletauth import WalletAuthDep, authorization_routes

app = FastAPI()
app.include_router(authorization_routes)

@app.get("/protected")
def protected(wa: WalletAuthDep):
    return wa.address
```

## Signing the challenge

The challenge is a serialized JSON object containing the following fields:

```python
message = {
    "chain": "ETH",
    "address": "0x...",
    "app": "myapp",
    "time": 1688819493.8691394
}
```

**PLEASE NOTE**: The `app` field needs to be set to the name of your application. This is used to prevent replay attacks.
```shell
export FASTAPI_WALLETAUTH_APP=myapp
```

The signature format depends on the wallet type and is specified in the `chain` field. This signature is then sent to the
`/authentication/solve` endpoint to obtain a Bearer token.

## Liability

This software is provided "as is" and "with all faults." I make no representations or warranties of any kind concerning
the safety, suitability, inaccuracies, typographical errors, or other harmful components of this
software. There are inherent dangers in the use of any software, especially cryptographic implementations. You are solely
responsible for determining whether this software is compatible with your machine and other software installed on your
computer. You are also solely responsible for the choice of a wallet and the security of your private keys. You
acknowledge and agree to waive any liability claim against me from any loss or damage of any kind arising out of or in
connection with your use of this software.
            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "fastapi-walletauth",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.1,<4.0",
    "maintainer_email": "",
    "keywords": "FastAPI,authentication,signature,wallet,ethereum,solana,web3,jwt",
    "author": "mhh",
    "author_email": "mike.hukiewitz@robotter.ai",
    "download_url": "https://files.pythonhosted.org/packages/05/09/f16f61a7268d782efadfcb340c76f82b121e6afd63311d62d8774e113e54/fastapi_walletauth-1.2.0.tar.gz",
    "platform": null,
    "description": "# FastAPI Wallet Authentication\n\nfastapi-walletauth provides a simple way to authenticate users in FastAPI applications using a wallet.\nIt currently supports Ethereum and Solana wallets/signatures.\n\n## Installation\n\n```shell\npip install fastapi-walletauth\n```\n\n## Usage\n\nAdding the authentication endpoints is as simple as importing the `authorization_routes` from `fastapi_walletauth`:\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_walletauth import authorization_routes\n\napp = FastAPI()\n\napp.include_router(authorization_routes)\n```\n\nThis will add the following endpoints to your application:\n\n- `POST /authentication/challenge`: Returns a challenge for the user to sign\n- `POST /authentication/solve`: Returns a Bearer token if the signature is valid\n- `POST /authentication/logout`: Invalidates the current token\n- `POST /authentication/refresh`: Returns a new token if the current token is valid\n\nYou can then use `WalletAuthDep` to protect your endpoints:\n\n```python\nfrom fastapi import FastAPI\nfrom fastapi_walletauth import WalletAuthDep, authorization_routes\n\napp = FastAPI()\napp.include_router(authorization_routes)\n\n@app.get(\"/protected\")\ndef protected(wa: WalletAuthDep):\n    return wa.address\n```\n\n## Signing the challenge\n\nThe challenge is a serialized JSON object containing the following fields:\n\n```python\nmessage = {\n    \"chain\": \"ETH\",\n    \"address\": \"0x...\",\n    \"app\": \"myapp\",\n    \"time\": 1688819493.8691394\n}\n```\n\n**PLEASE NOTE**: The `app` field needs to be set to the name of your application. This is used to prevent replay attacks.\n```shell\nexport FASTAPI_WALLETAUTH_APP=myapp\n```\n\nThe signature format depends on the wallet type and is specified in the `chain` field. This signature is then sent to the\n`/authentication/solve` endpoint to obtain a Bearer token.\n\n## Liability\n\nThis software is provided \"as is\" and \"with all faults.\" I make no representations or warranties of any kind concerning\nthe safety, suitability, inaccuracies, typographical errors, or other harmful components of this\nsoftware. There are inherent dangers in the use of any software, especially cryptographic implementations. You are solely\nresponsible for determining whether this software is compatible with your machine and other software installed on your\ncomputer. You are also solely responsible for the choice of a wallet and the security of your private keys. You\nacknowledge and agree to waive any liability claim against me from any loss or damage of any kind arising out of or in\nconnection with your use of this software.",
    "bugtrack_url": null,
    "license": "",
    "summary": "FastAPI extension for user authentication through signature challenges",
    "version": "1.2.0",
    "project_urls": null,
    "split_keywords": [
        "fastapi",
        "authentication",
        "signature",
        "wallet",
        "ethereum",
        "solana",
        "web3",
        "jwt"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "83c012ee731ea6f9f0df828daacc4d46e687bfb20b4856fbed21581e7c251b3f",
                "md5": "57017a063b9c4c1e34ace0d9f691d26b",
                "sha256": "0d5b50416f400cbce893ed194d48846f93595a4238068f3f3c2041e092753767"
            },
            "downloads": -1,
            "filename": "fastapi_walletauth-1.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "57017a063b9c4c1e34ace0d9f691d26b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8.1,<4.0",
            "size": 9403,
            "upload_time": "2023-10-13T18:21:54",
            "upload_time_iso_8601": "2023-10-13T18:21:54.793486Z",
            "url": "https://files.pythonhosted.org/packages/83/c0/12ee731ea6f9f0df828daacc4d46e687bfb20b4856fbed21581e7c251b3f/fastapi_walletauth-1.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "0509f16f61a7268d782efadfcb340c76f82b121e6afd63311d62d8774e113e54",
                "md5": "4ee26a25b7caac46352c02bf52811d10",
                "sha256": "91e89c11c3fdda58cead4df14a079e78475cb32cf09b80a08704de59d3592eb1"
            },
            "downloads": -1,
            "filename": "fastapi_walletauth-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "4ee26a25b7caac46352c02bf52811d10",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.1,<4.0",
            "size": 8017,
            "upload_time": "2023-10-13T18:21:56",
            "upload_time_iso_8601": "2023-10-13T18:21:56.063658Z",
            "url": "https://files.pythonhosted.org/packages/05/09/f16f61a7268d782efadfcb340c76f82b121e6afd63311d62d8774e113e54/fastapi_walletauth-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-10-13 18:21:56",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "fastapi-walletauth"
}
        
mhh
Elapsed time: 0.12355s