Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 13 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: ci

on:
push:
Expand All @@ -12,25 +12,23 @@ jobs:
name: lint ${{ matrix.python-version }}
strategy:
matrix:
python-version: [ '3.10', '3.11', '3.12' ]
python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14' ]
fail-fast: false
steps:
- uses: actions/checkout@v4

- name: Setup PDM
uses: pdm-project/setup-pdm@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install uv
uses: astral-sh/setup-uv@v3

- name: Set up Python ${{ matrix.python-version }}
run: uv python install ${{ matrix.python-version }}

- name: Install dependencies
run: |
pdm sync -dG lint

# - name: Run Tests
# run: |
# pdm run -v pytest tests
uv sync --group lint

- name: pre-commit
uses: pre-commit/action@v3.0.0
with:
extra_args: --all-files --verbose
- name: Run lint
run: |
source .venv/bin/activate
chmod 755 pre-commit.sh
./pre-commit.sh
21 changes: 17 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,28 @@ repos:
- id: check-toml

- repo: https://github.com/charliermarsh/ruff-pre-commit
rev: v0.11.4
rev: v0.14.0
hooks:
- id: ruff
args:
- '--fix'
- '--unsafe-fixes'
- id: ruff-format

- repo: https://github.com/pdm-project/pdm
rev: 2.23.0
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.9.0
hooks:
- id: pdm-lock-check
- id: uv-lock
- id: uv-export
args:
- '-o'
- 'requirements.txt'
- '--no-hashes'

- repo: local
hooks:
- id: ty
language: python
name: ty
pass_filenames: false
entry: uv run ty check fastapi_oauth20
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@

![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/fastapi-practices/fastapi_oauth20/ci.yml?logo=github)
[![GitHub](https://img.shields.io/github/license/wu-clan/httpfpt)](https://github.com/wu-clan/httpfpt/blob/master/LICENSE)
![Static Badge](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-blue)
![GitHub release (with filter)](https://img.shields.io/github/v/release/fastapi-practices/fastapi_oauth20)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

在 FastAPI 中异步授权 OAuth 2.0 客户端

我们的目标是集成多个 CN 第三方客户端,敬请期待(🐦)...
我们的目标是集成多个 CN 第三方客户端

## Download

```shell
pip install fastapi_oauth20
```

## Docs

[fastapi oauth20](https://fastapi-practices.github.io/fastapi-oauth20/)

## Sponsor

如果此项目能够帮助到你,你可以赞助作者一些咖啡豆表示鼓励:[:coffee: Sponsor :coffee:](https://wu-clan.github.io/sponsor/)
2 changes: 1 addition & 1 deletion fastapi_oauth20/integrations/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ async def __call__(
state: str | None = None,
code_verifier: str | None = None,
error: str | None = None,
) -> tuple[dict, str]:
) -> tuple[dict[str, Any], str | None]:
if code is None or error is not None:
raise OAuth20AuthorizeCallbackError(
status_code=400,
Expand Down
14 changes: 7 additions & 7 deletions fastapi_oauth20/oauth20.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import abc
import json

from typing import Literal, cast
from typing import Any, Literal, cast
from urllib.parse import urlencode

import httpx
Expand Down Expand Up @@ -102,7 +102,7 @@ async def get_authorization_url(

return f'{self.authorize_endpoint}?{urlencode(params)}'

async def get_access_token(self, code: str, redirect_uri: str, code_verifier: str | None = None) -> dict:
async def get_access_token(self, code: str, redirect_uri: str, code_verifier: str | None = None) -> dict[str, Any]:
"""
Get access token for given.

Expand Down Expand Up @@ -136,7 +136,7 @@ async def get_access_token(self, code: str, redirect_uri: str, code_verifier: st
result = self.get_json_result(response, err_class=AccessTokenError)
return result

async def refresh_token(self, refresh_token: str) -> dict:
async def refresh_token(self, refresh_token: str) -> dict[str, Any]:
"""
Get new access token by refresh token.

Expand Down Expand Up @@ -202,15 +202,15 @@ def raise_httpx_oauth20_errors(response: httpx.Response) -> None:
raise HTTPXOAuth20Error(str(e)) from e

@staticmethod
def get_json_result(response: httpx.Response, *, err_class: type[OAuth20RequestError]) -> dict:
def get_json_result(response: httpx.Response, *, err_class: type[OAuth20RequestError]) -> dict[str, Any]:
"""Get response json"""
try:
return cast(dict, response.json())
except json.decoder.JSONDecodeError as e:
return cast(dict[str, Any], response.json())
except json.JSONDecodeError as e:
raise err_class('Result serialization failed.', response) from e

@abc.abstractmethod
async def get_userinfo(self, access_token: str) -> dict:
async def get_userinfo(self, access_token: str) -> dict[str, Any]:
"""
Get user info from the API provider

Expand Down
Loading