## Telegram Auth Backend for FastAPI/Starlette
### INSTALL
In your FastAPI/Starlette app:
```bash
pip install xtg-auth
```
Add your Telegram Bot API Token to `.env` file as `TgBotToken`:
```dotenv
TgBotToken=0000000000:AAaaaAaAAAaaAAAAaaAAAaAAAaaAaaaaaAA
```
Before running add AuthenticationMiddleware to your app, and set TgAuth object with passed token as backend
```python
from fastapi import FastAPI
from starlette.middleware.authentication import AuthenticationMiddleware
from tg_ath import TgAuth
app = FastAPI()
TOKEN = env('TgBotToken')
app.add_middleware(AuthenticationMiddleware, backend=TgAuth(TOKEN))
```
### Using:
Protected endpoints expect `Telegram.WebApp.initData` string in `Authorization` header afrer `Tg` prefix in each request.
example:
```
Authorization: Tg user=%7B%22id%22%3A1038938370%2C%22first_name%22%3A%22Crypto%E2%86%94%EF%B8%8FFiat%22%2C%22last_name%22%3A%22%F0%9F%92%B5%F0%9F%92%B6%F0%9F%92%B3%22%2C%22username%22%3A%22ex212%22%2C%22language_code%22%3A%22en%22%2C%22allows_write_to_pm%22%3Atrue%7D&chat_instance=-6786124926491770465&chat_type=sender&auth_date=1729138692&hash=32e367eb6019007fdb2bd8f9a08628fb14ebc737df4a0dad3ecd2910b342f488
```
---
Made with ❤ on top of the [X-Model](https://github.com/XyncNet/x-model) and [Aiogram](https://github.com/aiogram/aiogram).
Raw data
{
"_id": null,
"home_page": null,
"name": "xtg-auth",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.12",
"maintainer_email": null,
"keywords": "starlette, fastapi, telegram, authentication, backend, auth",
"author": null,
"author_email": "Artemiev <mixartemev@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/9b/54/b0a7a6a052b0170a36a7ea47ebb85c3dcd210acac8dc11c2026c8e011ca5/xtg_auth-0.0.18.tar.gz",
"platform": null,
"description": "## Telegram Auth Backend for FastAPI/Starlette\n\n### INSTALL\n\nIn your FastAPI/Starlette app:\n```bash\npip install xtg-auth\n```\n\nAdd your Telegram Bot API Token to `.env` file as `TgBotToken`:\n```dotenv\nTgBotToken=0000000000:AAaaaAaAAAaaAAAAaaAAAaAAAaaAaaaaaAA\n```\n\nBefore running add AuthenticationMiddleware to your app, and set TgAuth object with passed token as backend\n```python\nfrom fastapi import FastAPI\nfrom starlette.middleware.authentication import AuthenticationMiddleware\nfrom tg_ath import TgAuth\n\napp = FastAPI()\nTOKEN = env('TgBotToken')\napp.add_middleware(AuthenticationMiddleware, backend=TgAuth(TOKEN))\n```\n\n### Using:\nProtected endpoints expect `Telegram.WebApp.initData` string in `Authorization` header afrer `Tg` prefix in each request.\n\nexample:\n```\nAuthorization: Tg user=%7B%22id%22%3A1038938370%2C%22first_name%22%3A%22Crypto%E2%86%94%EF%B8%8FFiat%22%2C%22last_name%22%3A%22%F0%9F%92%B5%F0%9F%92%B6%F0%9F%92%B3%22%2C%22username%22%3A%22ex212%22%2C%22language_code%22%3A%22en%22%2C%22allows_write_to_pm%22%3Atrue%7D&chat_instance=-6786124926491770465&chat_type=sender&auth_date=1729138692&hash=32e367eb6019007fdb2bd8f9a08628fb14ebc737df4a0dad3ecd2910b342f488 \n```\n\n---\nMade with \u2764 on top of the [X-Model](https://github.com/XyncNet/x-model) and [Aiogram](https://github.com/aiogram/aiogram).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Authentication backend for Telegram Mini Apps on starlette/fastapi API",
"version": "0.0.18",
"project_urls": {
"Homepage": "https://github.com/XyncNet/tg-auth",
"Repository": "https://github.com/XyncNet/tg-auth"
},
"split_keywords": [
"starlette",
" fastapi",
" telegram",
" authentication",
" backend",
" auth"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "80f946af289a232116a9b0e634040de328816d2e1d9d1ec7c3c923df1855ba70",
"md5": "0c767c41ba805237be9f42b8190f964c",
"sha256": "5ef355b890cea7117a5ea0649285b8e89ec70cc49e8cae472716a9527b0504b5"
},
"downloads": -1,
"filename": "xtg_auth-0.0.18-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0c767c41ba805237be9f42b8190f964c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.12",
"size": 4890,
"upload_time": "2024-12-09T19:30:22",
"upload_time_iso_8601": "2024-12-09T19:30:22.023421Z",
"url": "https://files.pythonhosted.org/packages/80/f9/46af289a232116a9b0e634040de328816d2e1d9d1ec7c3c923df1855ba70/xtg_auth-0.0.18-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9b54b0a7a6a052b0170a36a7ea47ebb85c3dcd210acac8dc11c2026c8e011ca5",
"md5": "697eb3278509398b615153af0372c510",
"sha256": "c34297b007e3f6a6fd6f58b16d79607bce42ba0ace4e4d22301a34970d91011a"
},
"downloads": -1,
"filename": "xtg_auth-0.0.18.tar.gz",
"has_sig": false,
"md5_digest": "697eb3278509398b615153af0372c510",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.12",
"size": 5252,
"upload_time": "2024-12-09T19:30:23",
"upload_time_iso_8601": "2024-12-09T19:30:23.225580Z",
"url": "https://files.pythonhosted.org/packages/9b/54/b0a7a6a052b0170a36a7ea47ebb85c3dcd210acac8dc11c2026c8e011ca5/xtg_auth-0.0.18.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-09 19:30:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "XyncNet",
"github_project": "tg-auth",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "xtg-auth"
}