teleapp-auth


Nameteleapp-auth JSON
Version 1.0.1 PyPI version JSON
download
home_pageNone
Summary🚀 A Rust-based Python package for validating Telegram WebApp authorization.
upload_time2024-09-19 06:21:59
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9.0
licenseMIT
keywords telegram webapp authentication auth web python api bot security miniapp teleapp teleapp-auth
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 🦀🐍 Telegram WebApp Auth Library
This library is a simple way to authenticate users in your web application using Telegram.

## Example

For a complete example, check out the [Example Bot repository](https://github.com/vffuunnyy/example_teleapp_auth).

## Installation

### Using pip

```bash
pip install teleapp-auth
```

### Using Poetry

```bash
poetry add teleapp-auth
```

### Using pipenv

```bash
pipenv install teleapp-auth
```

### Using uv

```bash
uv pip install teleapp-auth
```

## Usage

```python
from fastapi import Request, FastAPI
from teleapp_auth import get_secret_key, parse_webapp_data, validate_webapp_data


app = FastAPI()
secret_key = get_secret_key("BOT_TOKEN")


@app.post("/check_data")
async def check_data(request: Request) -> bool:
    request_json = await request.json()
    auth_data = request_json.get("auth_data")  # Telegram auth data from the request
    webapp_data = parse_webapp_data(auth_data)  # Parse the auth data to the WebAppInitData object

    # Example of the parsed data:
    # WebAppInitData {
    #   query_id: "AAEt6-JYAAAAAC3r4lj2oADQ",
    #   user: WebAppUser {
    #       id: 1,
    #       is_bot: None,
    #       first_name: "Test",
    #       last_name: "",
    #       username: "test",
    #       language_code: "ru",
    #       is_premium: None,
    #       added_to_attachment_menu: None,
    #       allows_write_to_pm: true,
    #       photo_url: None
    #   },
    #  receiver: None,
    #  chat: None,
    #  chat_type: None,
    #  chat_instance: None,
    #  start_param: None,
    #  can_send_after: None,
    #  auth_date: 1726572911,
    #  hash: "f87a5a37a5b487700a35cb1e3d2e92afa67e4b67066c9f1fa2c34986c2350b6e
    # }
    

    return validate_webapp_data(webapp_data, secret_key)  # True if the data is valid, False otherwise
```

## FAQ

### 1. What is the purpose of this library?
This library simplifies the process of authenticating users in your web application using Telegram WebApp authentication.

### 2. Can I get the user's profile photo with this library?
The `photo_url` field in the authentication data contains a URL to the user's profile photo. However, it is only available for Mini Apps launched from the attachment menu. Currently, integration with the attachment menu is [only accessible to major advertisers](https://core.telegram.org/bots/webapps#adding-bots-to-the-attachment-menu) on the Telegram Ad Platform. All bots can still test this feature in the test server environment by contacting Botfather on the test server.

### 3. Does this library automatically handle sending authentication data to my server?
No, you need to handle the process of sending the authentication data to your server. You can find an example of how to do this in the [page.html](https://github.com/vffuunnyy/teleapp_auth/blob/main/examples/page.html) file within the [examples](https://github.com/vffuunnyy/teleapp_auth/blob/main/examples) directory.

### 4. How do I validate the authentication data?
Use the `validate_webapp_data` function from the library to verify the authenticity of the data. This function compares the data with a secret key derived from your bot's token.

### 5. Can I use this library with any Python web framework?
Yes, the library is framework-agnostic, though [examples](https://github.com/vffuunnyy/teleapp_auth/blob/main/examples) are provided with [FastAPI](https://github.com/vffuunnyy/teleapp_auth/blob/main/examples/fastapi_server.py) and [Blacksheep](https://github.com/vffuunnyy/teleapp_auth/blob/main/examples/blacksheep_server.py). You can adapt it to other frameworks with minimal effort.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "teleapp-auth",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9.0",
    "maintainer_email": null,
    "keywords": "telegram, webapp, authentication, auth, web, python, api, bot, security, miniapp, teleapp, teleapp-auth",
    "author": null,
    "author_email": "vffuunnyy <vffuunnyy@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a0/70/d629b273ce74b57b0f566c6890be080cf6ae0881b8a3deb58ea1afaf64a6/teleapp_auth-1.0.1.tar.gz",
    "platform": null,
    "description": "# \ud83e\udd80\ud83d\udc0d Telegram WebApp Auth Library\nThis library is a simple way to authenticate users in your web application using Telegram.\n\n## Example\n\nFor a complete example, check out the [Example Bot repository](https://github.com/vffuunnyy/example_teleapp_auth).\n\n## Installation\n\n### Using pip\n\n```bash\npip install teleapp-auth\n```\n\n### Using Poetry\n\n```bash\npoetry add teleapp-auth\n```\n\n### Using pipenv\n\n```bash\npipenv install teleapp-auth\n```\n\n### Using uv\n\n```bash\nuv pip install teleapp-auth\n```\n\n## Usage\n\n```python\nfrom fastapi import Request, FastAPI\nfrom teleapp_auth import get_secret_key, parse_webapp_data, validate_webapp_data\n\n\napp = FastAPI()\nsecret_key = get_secret_key(\"BOT_TOKEN\")\n\n\n@app.post(\"/check_data\")\nasync def check_data(request: Request) -> bool:\n    request_json = await request.json()\n    auth_data = request_json.get(\"auth_data\")  # Telegram auth data from the request\n    webapp_data = parse_webapp_data(auth_data)  # Parse the auth data to the WebAppInitData object\n\n    # Example of the parsed data:\n    # WebAppInitData {\n    #   query_id: \"AAEt6-JYAAAAAC3r4lj2oADQ\",\n    #   user: WebAppUser {\n    #       id: 1,\n    #       is_bot: None,\n    #       first_name: \"Test\",\n    #       last_name: \"\",\n    #       username: \"test\",\n    #       language_code: \"ru\",\n    #       is_premium: None,\n    #       added_to_attachment_menu: None,\n    #       allows_write_to_pm: true,\n    #       photo_url: None\n    #   },\n    #  receiver: None,\n    #  chat: None,\n    #  chat_type: None,\n    #  chat_instance: None,\n    #  start_param: None,\n    #  can_send_after: None,\n    #  auth_date: 1726572911,\n    #  hash: \"f87a5a37a5b487700a35cb1e3d2e92afa67e4b67066c9f1fa2c34986c2350b6e\n    # }\n    \n\n    return validate_webapp_data(webapp_data, secret_key)  # True if the data is valid, False otherwise\n```\n\n## FAQ\n\n### 1. What is the purpose of this library?\nThis library simplifies the process of authenticating users in your web application using Telegram WebApp authentication.\n\n### 2. Can I get the user's profile photo with this library?\nThe `photo_url` field in the authentication data contains a URL to the user's profile photo. However, it is only available for Mini Apps launched from the attachment menu. Currently, integration with the attachment menu is [only accessible to major advertisers](https://core.telegram.org/bots/webapps#adding-bots-to-the-attachment-menu) on the Telegram Ad Platform. All bots can still test this feature in the test server environment by contacting Botfather on the test server.\n\n### 3. Does this library automatically handle sending authentication data to my server?\nNo, you need to handle the process of sending the authentication data to your server. You can find an example of how to do this in the [page.html](https://github.com/vffuunnyy/teleapp_auth/blob/main/examples/page.html) file within the [examples](https://github.com/vffuunnyy/teleapp_auth/blob/main/examples) directory.\n\n### 4. How do I validate the authentication data?\nUse the `validate_webapp_data` function from the library to verify the authenticity of the data. This function compares the data with a secret key derived from your bot's token.\n\n### 5. Can I use this library with any Python web framework?\nYes, the library is framework-agnostic, though [examples](https://github.com/vffuunnyy/teleapp_auth/blob/main/examples) are provided with [FastAPI](https://github.com/vffuunnyy/teleapp_auth/blob/main/examples/fastapi_server.py) and [Blacksheep](https://github.com/vffuunnyy/teleapp_auth/blob/main/examples/blacksheep_server.py). You can adapt it to other frameworks with minimal effort.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "\ud83d\ude80 A Rust-based Python package for validating Telegram WebApp authorization.",
    "version": "1.0.1",
    "project_urls": {
        "Documentation": "https://github.com/vffuunnyy/teleapp_auth/",
        "Homepage": "https://github.com/vffuunnyy/teleapp_auth/",
        "Issues": "https://github.com/vffuunnyy/teleapp_auth/issues",
        "Repository": "https://github.com/vffuunnyy/teleapp_auth.git"
    },
    "split_keywords": [
        "telegram",
        " webapp",
        " authentication",
        " auth",
        " web",
        " python",
        " api",
        " bot",
        " security",
        " miniapp",
        " teleapp",
        " teleapp-auth"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4103a195cb6d243b5c37907bd7e5ebd6f8de362af7eca97512a250efada84daf",
                "md5": "e59602765c052797125baba3f9bfb925",
                "sha256": "da3a03d482eb9375a501f075a96c5b61dbae2879cc7cf6b34377d2981f3b69bd"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp310-cp310-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "e59602765c052797125baba3f9bfb925",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.9.0",
            "size": 219895,
            "upload_time": "2024-09-19T06:21:41",
            "upload_time_iso_8601": "2024-09-19T06:21:41.890189Z",
            "url": "https://files.pythonhosted.org/packages/41/03/a195cb6d243b5c37907bd7e5ebd6f8de362af7eca97512a250efada84daf/teleapp_auth-1.0.1-cp310-cp310-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3980f4e543b208ad4e27f4e907519f87b2433bdd4ed24ce6510fd5749bca3c3d",
                "md5": "babc59bf8228544064e5ab8659f0e213",
                "sha256": "556be146b5e930eb428aeb6f2ec8d3b26e9e70b97df362e466ddcde4698af0ea"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp310-cp310-manylinux_2_34_x86_64.whl",
            "has_sig": false,
            "md5_digest": "babc59bf8228544064e5ab8659f0e213",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.9.0",
            "size": 252698,
            "upload_time": "2024-09-19T06:21:48",
            "upload_time_iso_8601": "2024-09-19T06:21:48.257947Z",
            "url": "https://files.pythonhosted.org/packages/39/80/f4e543b208ad4e27f4e907519f87b2433bdd4ed24ce6510fd5749bca3c3d/teleapp_auth-1.0.1-cp310-cp310-manylinux_2_34_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "dbb4264f96bc149d953c582d41a67a579f445000def8938a44795dc2350762ce",
                "md5": "cd0d1b0a41ed8dca1c333e87106ee9dc",
                "sha256": "bdf41c8034deda88b8954eed3d463f6c501d3b933d6c87c7001776548d018b52"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp310-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "cd0d1b0a41ed8dca1c333e87106ee9dc",
            "packagetype": "bdist_wheel",
            "python_version": "cp310",
            "requires_python": ">=3.9.0",
            "size": 158807,
            "upload_time": "2024-09-19T06:21:54",
            "upload_time_iso_8601": "2024-09-19T06:21:54.027231Z",
            "url": "https://files.pythonhosted.org/packages/db/b4/264f96bc149d953c582d41a67a579f445000def8938a44795dc2350762ce/teleapp_auth-1.0.1-cp310-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b543ee36ec6ed1f6fd5bef8d18bcc559cf8f2e4d8f1f96a37ebce06273a24a03",
                "md5": "f491933f1ed1c0cb8f7bf48714bacd15",
                "sha256": "9f96ba9fd70eb4bac889a232f246641d24c66694d87079864a55a7940f8c7430"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp311-cp311-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "f491933f1ed1c0cb8f7bf48714bacd15",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.9.0",
            "size": 219823,
            "upload_time": "2024-09-19T06:21:43",
            "upload_time_iso_8601": "2024-09-19T06:21:43.594043Z",
            "url": "https://files.pythonhosted.org/packages/b5/43/ee36ec6ed1f6fd5bef8d18bcc559cf8f2e4d8f1f96a37ebce06273a24a03/teleapp_auth-1.0.1-cp311-cp311-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "8f575e21e37a14c1b55265de5abf3b66e799017f937a9ccddd38f37e63f99d0f",
                "md5": "81f912462d4c65bb16cb217c7cb6cd88",
                "sha256": "6e159f1d2cba2bb9be9e8f320b4bbeac37d63bc4a19fb0852313becd4af741da"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp311-cp311-manylinux_2_34_x86_64.whl",
            "has_sig": false,
            "md5_digest": "81f912462d4c65bb16cb217c7cb6cd88",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.9.0",
            "size": 252536,
            "upload_time": "2024-09-19T06:21:49",
            "upload_time_iso_8601": "2024-09-19T06:21:49.838497Z",
            "url": "https://files.pythonhosted.org/packages/8f/57/5e21e37a14c1b55265de5abf3b66e799017f937a9ccddd38f37e63f99d0f/teleapp_auth-1.0.1-cp311-cp311-manylinux_2_34_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "79ee9becf9c04099dcf55f3b914555ff54541aafb03b6c9c46d0eb3eb99b3ce3",
                "md5": "f1dcb3fffce392a927d3001e7ef21823",
                "sha256": "515528f57a60f36357938ab9e5e624e861c86da1a61f265456b432f474682064"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp311-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "f1dcb3fffce392a927d3001e7ef21823",
            "packagetype": "bdist_wheel",
            "python_version": "cp311",
            "requires_python": ">=3.9.0",
            "size": 158722,
            "upload_time": "2024-09-19T06:21:55",
            "upload_time_iso_8601": "2024-09-19T06:21:55.063742Z",
            "url": "https://files.pythonhosted.org/packages/79/ee/9becf9c04099dcf55f3b914555ff54541aafb03b6c9c46d0eb3eb99b3ce3/teleapp_auth-1.0.1-cp311-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4b89c015548bfbe1923b82023f5c9f920b323e9a2784bb6bb5886194ed95f4a4",
                "md5": "7038d53f1c78830fc888057a5cd55fa9",
                "sha256": "f4a511bbf4464002ff033beeadaca8053e4ec962db2a7a3a25be6aa9d405e8f0"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp312-cp312-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "7038d53f1c78830fc888057a5cd55fa9",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.9.0",
            "size": 219146,
            "upload_time": "2024-09-19T06:21:45",
            "upload_time_iso_8601": "2024-09-19T06:21:45.039041Z",
            "url": "https://files.pythonhosted.org/packages/4b/89/c015548bfbe1923b82023f5c9f920b323e9a2784bb6bb5886194ed95f4a4/teleapp_auth-1.0.1-cp312-cp312-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c0bd0df24afe5e4d7d7aaeffc863540634e1a1a6d9f3ba21d55c53766e86f697",
                "md5": "c1dfd8364d02541ccca0fc17fe9a377a",
                "sha256": "0a6ab50e0bd4fee7855b90c2d4af6d535290bef2ec6b625ff19f13dcea95779d"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp312-cp312-manylinux_2_34_x86_64.whl",
            "has_sig": false,
            "md5_digest": "c1dfd8364d02541ccca0fc17fe9a377a",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.9.0",
            "size": 251839,
            "upload_time": "2024-09-19T06:21:51",
            "upload_time_iso_8601": "2024-09-19T06:21:51.011753Z",
            "url": "https://files.pythonhosted.org/packages/c0/bd/0df24afe5e4d7d7aaeffc863540634e1a1a6d9f3ba21d55c53766e86f697/teleapp_auth-1.0.1-cp312-cp312-manylinux_2_34_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a1d676da320cf1963aa29e77596647169d7a03c6d50503df0641dcc2b6a5a265",
                "md5": "1a9117ef362816d859dff940f80165b7",
                "sha256": "b6242fce914d834fd422ed9b42cd6ee159300b27dd8330d3c6dbb5a12a1ddab3"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp312-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "1a9117ef362816d859dff940f80165b7",
            "packagetype": "bdist_wheel",
            "python_version": "cp312",
            "requires_python": ">=3.9.0",
            "size": 157931,
            "upload_time": "2024-09-19T06:21:56",
            "upload_time_iso_8601": "2024-09-19T06:21:56.243716Z",
            "url": "https://files.pythonhosted.org/packages/a1/d6/76da320cf1963aa29e77596647169d7a03c6d50503df0641dcc2b6a5a265/teleapp_auth-1.0.1-cp312-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "61e2c79dab7c657a0bae64908a2039881a2dabacc6bb6e66ec484b59a946cf27",
                "md5": "2eb9e277812619d90ed7448e7373b9f2",
                "sha256": "6ca8726bab27620bb2438ac89d74402b9ec040671653eb0f9fe16ab7072bdbd0"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp39-cp39-macosx_11_0_arm64.whl",
            "has_sig": false,
            "md5_digest": "2eb9e277812619d90ed7448e7373b9f2",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9.0",
            "size": 220324,
            "upload_time": "2024-09-19T06:21:46",
            "upload_time_iso_8601": "2024-09-19T06:21:46.717615Z",
            "url": "https://files.pythonhosted.org/packages/61/e2/c79dab7c657a0bae64908a2039881a2dabacc6bb6e66ec484b59a946cf27/teleapp_auth-1.0.1-cp39-cp39-macosx_11_0_arm64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "32407d761934006d1ea4966a5b17eb7727390a8f3f8623edd02cbd0335b02788",
                "md5": "a9099b6dbf59976898a68e8699fb7cbc",
                "sha256": "34d8d78d881839466b18dfeba5e659bdf3fc6fb2d8729e95fc7f5f38dc11a6ae"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp39-cp39-manylinux_2_34_x86_64.whl",
            "has_sig": false,
            "md5_digest": "a9099b6dbf59976898a68e8699fb7cbc",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9.0",
            "size": 253082,
            "upload_time": "2024-09-19T06:21:52",
            "upload_time_iso_8601": "2024-09-19T06:21:52.255646Z",
            "url": "https://files.pythonhosted.org/packages/32/40/7d761934006d1ea4966a5b17eb7727390a8f3f8623edd02cbd0335b02788/teleapp_auth-1.0.1-cp39-cp39-manylinux_2_34_x86_64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "fe18840d025033277ac2b20a4bec60d98ad98fd464486e9c3eb7e6a4956b3035",
                "md5": "3e5db38587df0dec824789390c6219bb",
                "sha256": "c9d438ff48a0f6c303126fdb18ea41fe20432f7088fdb459eda71a44ab3aa8d5"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1-cp39-none-win_amd64.whl",
            "has_sig": false,
            "md5_digest": "3e5db38587df0dec824789390c6219bb",
            "packagetype": "bdist_wheel",
            "python_version": "cp39",
            "requires_python": ">=3.9.0",
            "size": 159388,
            "upload_time": "2024-09-19T06:21:57",
            "upload_time_iso_8601": "2024-09-19T06:21:57.632423Z",
            "url": "https://files.pythonhosted.org/packages/fe/18/840d025033277ac2b20a4bec60d98ad98fd464486e9c3eb7e6a4956b3035/teleapp_auth-1.0.1-cp39-none-win_amd64.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a070d629b273ce74b57b0f566c6890be080cf6ae0881b8a3deb58ea1afaf64a6",
                "md5": "727c99586d281d8f782e96dfb70899a8",
                "sha256": "0439a569789f97cf93f1893bfe8a6b95d1b60abf452fe010e5bbc0ccedf80ef2"
            },
            "downloads": -1,
            "filename": "teleapp_auth-1.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "727c99586d281d8f782e96dfb70899a8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9.0",
            "size": 12855,
            "upload_time": "2024-09-19T06:21:59",
            "upload_time_iso_8601": "2024-09-19T06:21:59.317823Z",
            "url": "https://files.pythonhosted.org/packages/a0/70/d629b273ce74b57b0f566c6890be080cf6ae0881b8a3deb58ea1afaf64a6/teleapp_auth-1.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-09-19 06:21:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vffuunnyy",
    "github_project": "teleapp_auth",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "teleapp-auth"
}
        
Elapsed time: 0.41710s