aiohttp-oauth2-session


Nameaiohttp-oauth2-session JSON
Version 0.1.1 PyPI version JSON
download
home_pagehttps://github.com/Cikmo/OAuth2Session
SummaryA fully typed, package that adds OAuth2 support for aiohttp.ClientSession.
upload_time2022-12-21 01:40:38
maintainer
docs_urlNone
authorCikmo
requires_python>=3.10,<4.0
licenseMIT
keywords aiohttp oauth oauth2 oauthlib session
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # aiohttp-oauth2-session

A fully typed package that adds OAuth2 support for aiohttp.ClientSession.

## Installation

```bash
pip install aiohttp-oauth2-session
```

## Basic Usage

```python
from aiohttp_oauth2_session import OAuth2Session
```

You can create a session with or without a token already known.

```python
token = {
    "access_token": "abc1234",
    "token_type": "Bearer",
    "expires_in": 3600,
    "refresh_token": "def5678",
}

session = OAuth2Session(
    client_id="client_id",
    client_secret="client_secret",
    redirect_uri="https://example.com/oauth/redirect",
    scope="scope1 scope2",
    token=token,
)

# Which allows you to make authenticated requests straight away.
resp = await session.get("https://example.com/api/resource")
await session.close()
```

You can also create a session without a token and fetch one later.

```python
session = OAuth2Session(
    client_id="client_id",
    client_secret="client_secret",
    redirect_uri="https://example.com/oauth/redirect",
    scope="scope1 scope2",
)

await session.fetch_token(
    token_url="https://example.com/oauth/token",
    authorization_response="https://example.com/oauth/redirect?code=abc1234",
)

# now you can make authenticated requests.
resp = await session.get("https://example.com/api/resource")
await session.close()
```

You can also use context managers to automatically close the session.

```python
async with OAuth2Session(
    client_id="client_id",
    client_secret="client_secret",
    redirect_uri="https://example.com/oauth/redirect",
    scope="scope1 scope2",
) as session:
    await session.fetch_token(
        token_url="https://example.com/oauth/token",
        authorization_response="https://example.com/oauth/redirect?code=abc1234",
    )
    async with session.get("https://example.com/api/resource") as resp:
        print(await resp.json())
```

## Feel free to contribute!

What still needs to be done:

- [ ] Add more comprehensive tests
- [ ] Add typed support for other aiohttp client sessions
- [ ] Expand the depency versions to be less restrictive
- [ ] Make the code more readable, it's a bit messy right now
- [ ] Whatever else you can think of. Please do open an issue or PR!

---

This package is based on [a gist](https://gist.github.com/kellerza/5ca798f49983bb702bc6e7a05ba53def) by [kellerza](https://gist.github.com/kellerza). Thank you very much!


            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/Cikmo/OAuth2Session",
    "name": "aiohttp-oauth2-session",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "aiohttp,oauth,oauth2,oauthlib,session",
    "author": "Cikmo",
    "author_email": "59421913+Cikmo@users.noreply.github.com",
    "download_url": "https://files.pythonhosted.org/packages/fe/d8/18b5a5835c0e6e3feda9efefb6b5b4cb080f0e733e289e6b93028086a4fe/aiohttp_oauth2_session-0.1.1.tar.gz",
    "platform": null,
    "description": "# aiohttp-oauth2-session\n\nA fully typed package that adds OAuth2 support for aiohttp.ClientSession.\n\n## Installation\n\n```bash\npip install aiohttp-oauth2-session\n```\n\n## Basic Usage\n\n```python\nfrom aiohttp_oauth2_session import OAuth2Session\n```\n\nYou can create a session with or without a token already known.\n\n```python\ntoken = {\n    \"access_token\": \"abc1234\",\n    \"token_type\": \"Bearer\",\n    \"expires_in\": 3600,\n    \"refresh_token\": \"def5678\",\n}\n\nsession = OAuth2Session(\n    client_id=\"client_id\",\n    client_secret=\"client_secret\",\n    redirect_uri=\"https://example.com/oauth/redirect\",\n    scope=\"scope1 scope2\",\n    token=token,\n)\n\n# Which allows you to make authenticated requests straight away.\nresp = await session.get(\"https://example.com/api/resource\")\nawait session.close()\n```\n\nYou can also create a session without a token and fetch one later.\n\n```python\nsession = OAuth2Session(\n    client_id=\"client_id\",\n    client_secret=\"client_secret\",\n    redirect_uri=\"https://example.com/oauth/redirect\",\n    scope=\"scope1 scope2\",\n)\n\nawait session.fetch_token(\n    token_url=\"https://example.com/oauth/token\",\n    authorization_response=\"https://example.com/oauth/redirect?code=abc1234\",\n)\n\n# now you can make authenticated requests.\nresp = await session.get(\"https://example.com/api/resource\")\nawait session.close()\n```\n\nYou can also use context managers to automatically close the session.\n\n```python\nasync with OAuth2Session(\n    client_id=\"client_id\",\n    client_secret=\"client_secret\",\n    redirect_uri=\"https://example.com/oauth/redirect\",\n    scope=\"scope1 scope2\",\n) as session:\n    await session.fetch_token(\n        token_url=\"https://example.com/oauth/token\",\n        authorization_response=\"https://example.com/oauth/redirect?code=abc1234\",\n    )\n    async with session.get(\"https://example.com/api/resource\") as resp:\n        print(await resp.json())\n```\n\n## Feel free to contribute!\n\nWhat still needs to be done:\n\n- [ ] Add more comprehensive tests\n- [ ] Add typed support for other aiohttp client sessions\n- [ ] Expand the depency versions to be less restrictive\n- [ ] Make the code more readable, it's a bit messy right now\n- [ ] Whatever else you can think of. Please do open an issue or PR!\n\n---\n\nThis package is based on [a gist](https://gist.github.com/kellerza/5ca798f49983bb702bc6e7a05ba53def) by [kellerza](https://gist.github.com/kellerza). Thank you very much!\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A fully typed, package that adds OAuth2 support for aiohttp.ClientSession.",
    "version": "0.1.1",
    "split_keywords": [
        "aiohttp",
        "oauth",
        "oauth2",
        "oauthlib",
        "session"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "816ec85f13b4fb6023f6c04c692c9365",
                "sha256": "2feb3f87793e100041b7973dc3c2bc0bce323b034a7d7007d3e5c77798353bf8"
            },
            "downloads": -1,
            "filename": "aiohttp_oauth2_session-0.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "816ec85f13b4fb6023f6c04c692c9365",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 7945,
            "upload_time": "2022-12-21T01:40:36",
            "upload_time_iso_8601": "2022-12-21T01:40:36.961168Z",
            "url": "https://files.pythonhosted.org/packages/66/f0/4e43abbd08055eaa198d9f43c01109ad31774e3d76695bd5f4552a674976/aiohttp_oauth2_session-0.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "ac02793621597b94536993986185d038",
                "sha256": "3cbbca57918fb61f98197b4d5cbbdd3b17e38a2f6b0ae1c8ac71ca8827da9c2a"
            },
            "downloads": -1,
            "filename": "aiohttp_oauth2_session-0.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "ac02793621597b94536993986185d038",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 7832,
            "upload_time": "2022-12-21T01:40:38",
            "upload_time_iso_8601": "2022-12-21T01:40:38.396000Z",
            "url": "https://files.pythonhosted.org/packages/fe/d8/18b5a5835c0e6e3feda9efefb6b5b4cb080f0e733e289e6b93028086a4fe/aiohttp_oauth2_session-0.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-21 01:40:38",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "Cikmo",
    "github_project": "OAuth2Session",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "aiohttp-oauth2-session"
}
        
Elapsed time: 0.02139s