Skip to content

Commit 2487ba4

Browse files
committed
feat: refactor api
1 parent 5672052 commit 2487ba4

File tree

23 files changed

+422
-316
lines changed

23 files changed

+422
-316
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/codeql.yml

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
# ******** NOTE ********
8+
# We have attempted to detect the languages in your repository. Please check
9+
# the `language` matrix defined below to confirm you have the correct set of
10+
# supported CodeQL languages.
11+
#
12+
name: "CodeQL Advanced"
13+
14+
on:
15+
push:
16+
branches: [ "master" ]
17+
pull_request:
18+
branches: [ "master" ]
19+
schedule:
20+
- cron: '37 9 * * 4'
21+
22+
jobs:
23+
analyze:
24+
name: Analyze (${{ matrix.language }})
25+
# Runner size impacts CodeQL analysis time. To learn more, please see:
26+
# - https://gh.io/recommended-hardware-resources-for-running-codeql
27+
# - https://gh.io/supported-runners-and-hardware-resources
28+
# - https://gh.io/using-larger-runners (GitHub.com only)
29+
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
30+
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
31+
permissions:
32+
# required for all workflows
33+
security-events: write
34+
35+
# required to fetch internal or private CodeQL packs
36+
packages: read
37+
38+
# only required for workflows in private repositories
39+
actions: read
40+
contents: read
41+
42+
strategy:
43+
fail-fast: false
44+
matrix:
45+
include:
46+
- language: python
47+
build-mode: none
48+
# CodeQL supports the following values keywords for 'language': 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'swift'
49+
# Use `c-cpp` to analyze code written in C, C++ or both
50+
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
51+
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
52+
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
53+
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
54+
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
55+
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
56+
steps:
57+
- name: Checkout repository
58+
uses: actions/checkout@v4
59+
60+
# Initializes the CodeQL tools for scanning.
61+
- name: Initialize CodeQL
62+
uses: github/codeql-action/init@v3
63+
with:
64+
languages: ${{ matrix.language }}
65+
build-mode: ${{ matrix.build-mode }}
66+
# If you wish to specify custom queries, you can do so here or in a config file.
67+
# By default, queries listed here will override any specified in a config file.
68+
# Prefix the list here with "+" to use these queries and those in the config file.
69+
70+
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
71+
# queries: security-extended,security-and-quality
72+
73+
# If the analyze step fails for one of the languages you are analyzing with
74+
# "We were unable to automatically build your code", modify the matrix above
75+
# to set the build mode to "manual" for that language. Then modify this step
76+
# to build your code.
77+
# ℹ️ Command-line programs to run using the OS shell.
78+
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
79+
- if: matrix.build-mode == 'manual'
80+
shell: bash
81+
run: |
82+
echo 'If you are using a "manual" build mode for one or more of the' \
83+
'languages you are analyzing, replace this with the commands to build' \
84+
'your code, for example:'
85+
echo ' make bootstrap'
86+
echo ' make release'
87+
exit 1
88+
89+
- name: Perform CodeQL Analysis
90+
uses: github/codeql-action/analyze@v3
91+
with:
92+
category: "/language:${{matrix.language}}"

.github/workflows/test.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Run all tests
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
types:
9+
- opened
10+
- synchronize
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Set up Python 3.12
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: 3.12
23+
24+
- name: Install dependencies
25+
run: |
26+
pip install poetry
27+
poetry config virtualenvs.create false
28+
poetry install --only dev
29+
30+
- name: Run checks
31+
run: |
32+
poetry run make lint

README.md

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
# FastLink
22

3-
**Effortless asynchronous OAuth 2.0 client for popular platforms**
3+
_OAuth 2.0 client for various platforms, asynchronous, easy-to-use, extensible_
44

55
---
66

7-
[![Test](https://github.com/everysoftware/fastid/actions/workflows/test.yml/badge.svg)](https://github.com/everysoftware/fastid/actions/workflows/test.yml)
8-
[![CodeQL Advanced](https://github.com/everysoftware/fastid/actions/workflows/codeql.yml/badge.svg)](https://github.com/everysoftware/fastid/actions/workflows/codeql.yml)
7+
[![Test](https://github.com/everysoftware/fastlink/actions/workflows/test.yml/badge.svg)](https://github.com/everysoftware/fastlink/actions/workflows/test.yml)
8+
[![CodeQL Advanced](https://github.com/everysoftware/fastlink/actions/workflows/codeql.yml/badge.svg)](https://github.com/everysoftware/fastlink/actions/workflows/codeql.yml)
99

1010
---
1111

1212
## Features
1313

14+
- **All-in-one**: Supports popular platforms like **Google**, **Yandex**, **Telegram**, etc.
1415
- **Asynchronous**: Built on top of `httpx` is fully asynchronous.
15-
- **Built-in support**: For popular OAuth 2.0 providers like **Google**, **Yandex**, **Telegram**, etc.
16-
- **Extensible**: Easily add support for new OAuth 2.0 providers.
17-
- **Easy to use**: Simple and intuitive API.
16+
- **Easy-to-use**: Simple and intuitive API for quick integration.
17+
- **Extensible**: Easily add support for new platforms or customize existing ones.
1818

1919
## Installation
2020

@@ -27,16 +27,16 @@ pip install fastlink
2727
```python
2828
from typing import Annotated
2929

30-
from fastapi import FastAPI, Depends
31-
from starlette.responses import RedirectResponse
30+
from fastapi import Depends, FastAPI
31+
from fastapi.responses import RedirectResponse
3232

33-
from fastlink.google.client import GoogleOAuth
34-
from fastlink.schemas import OAuth2Callback, OpenID
3533
from examples.config import settings
34+
from fastlink import GoogleSSO
35+
from fastlink.schemas import OAuth2Callback, OpenID
3636

3737
app = FastAPI()
3838

39-
oauth = GoogleOAuth(
39+
oauth = GoogleSSO(
4040
settings.google_client_id,
4141
settings.google_client_secret,
4242
"http://localhost:8000/callback",
@@ -46,15 +46,14 @@ oauth = GoogleOAuth(
4646
@app.get("/login")
4747
async def login() -> RedirectResponse:
4848
async with oauth:
49-
url = await oauth.get_authorization_url()
49+
url = await oauth.login_url()
5050
return RedirectResponse(url=url)
5151

5252

5353
@app.get("/callback")
54-
async def oauth_callback(callback: Annotated[OAuth2Callback, Depends()]) -> OpenID:
54+
async def callback(call: Annotated[OAuth2Callback, Depends()]) -> OpenID:
5555
async with oauth:
56-
await oauth.authorize(callback)
57-
return await oauth.userinfo()
56+
return await oauth.callback(call)
5857

5958
```
6059

examples/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class Settings(BaseSettings):
88
yandex_client_id: str
99
yandex_client_secret: str
1010

11-
telegram_bot_username: str
1211
telegram_bot_token: str
12+
telegram_bot_public_key: str
1313

1414
model_config = SettingsConfigDict(env_file=".env", extra="ignore")
1515

examples/google.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
from typing import Annotated
22

33
from fastapi import Depends, FastAPI
4-
from starlette.responses import RedirectResponse
4+
from fastapi.responses import RedirectResponse
55

66
from examples.config import settings
7-
from fastlink import GoogleOAuth
7+
from fastlink import GoogleSSO
88
from fastlink.schemas import OAuth2Callback, OpenID
99

1010
app = FastAPI()
1111

12-
oauth = GoogleOAuth(
12+
oauth = GoogleSSO(
1313
settings.google_client_id,
1414
settings.google_client_secret,
1515
"http://localhost:8000/callback",
@@ -19,12 +19,11 @@
1919
@app.get("/login")
2020
async def login() -> RedirectResponse:
2121
async with oauth:
22-
url = await oauth.get_authorization_url()
22+
url = await oauth.login_url()
2323
return RedirectResponse(url=url)
2424

2525

2626
@app.get("/callback")
27-
async def oauth_callback(callback: Annotated[OAuth2Callback, Depends()]) -> OpenID:
27+
async def callback(call: Annotated[OAuth2Callback, Depends()]) -> OpenID:
2828
async with oauth:
29-
await oauth.authorize(callback)
30-
return await oauth.userinfo()
29+
return await oauth.callback(call)

examples/telegram.py

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,33 @@
1-
from typing import Annotated, Any
1+
from typing import Annotated
22

33
from fastapi import Depends, FastAPI
44
from fastapi.responses import HTMLResponse, RedirectResponse
55

66
from examples.config import settings
7-
from fastlink import TelegramAuth
7+
from fastlink import TelegramSSO
88
from fastlink.schemas import OpenID
99
from fastlink.telegram.schemas import TelegramCallback
1010

1111
app = FastAPI()
1212

13-
oauth = TelegramAuth(
14-
settings.telegram_bot_token,
15-
"http://localhost:8000/widget",
16-
)
17-
CALLBACK_URL = "http://localhost:8000/callback"
13+
oauth = TelegramSSO(settings.telegram_bot_token, "http://localhost:8000/widget", "http://localhost:8000/callback")
1814

1915

2016
@app.get("/login")
2117
async def login() -> RedirectResponse:
2218
async with oauth:
23-
url = await oauth.get_authorization_url()
19+
url = await oauth.login_url()
2420
return RedirectResponse(url=url)
2521

2622

2723
@app.get("/widget")
28-
def oauth_redirect() -> Any:
29-
text = f"""
30-
<html>
31-
<head>
32-
<title>Telegram OAuth</title>
33-
</head>
34-
<body>
35-
<script async src="https://telegram.org/js/telegram-widget.js?22" data-telegram-login="{settings.telegram_bot_username}"
36-
data-size="medium" data-auth-url="{CALLBACK_URL}" data-request-access="write"></script>
37-
</body>
38-
</html>
39-
"""
40-
return HTMLResponse(content=text)
24+
async def widget() -> HTMLResponse:
25+
async with oauth:
26+
content = await oauth.widget()
27+
return HTMLResponse(content=content)
4128

4229

4330
@app.get("/callback")
44-
async def oauth_callback(callback: Annotated[TelegramCallback, Depends()]) -> OpenID:
31+
async def callback(call: Annotated[TelegramCallback, Depends()]) -> OpenID:
4532
async with oauth:
46-
await oauth.authorize(callback)
47-
return await oauth.userinfo()
33+
return await oauth.callback(call)

examples/yandex.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
from starlette.responses import RedirectResponse
55

66
from examples.config import settings
7-
from fastlink import YandexOAuth
7+
from fastlink import YandexSSO
88
from fastlink.schemas import OAuth2Callback, OpenID
99

1010
app = FastAPI()
1111

12-
oauth = YandexOAuth(
12+
oauth = YandexSSO(
1313
settings.yandex_client_id,
1414
settings.yandex_client_secret,
1515
"http://localhost:8000/callback",
@@ -19,12 +19,11 @@
1919
@app.get("/login")
2020
async def login() -> RedirectResponse:
2121
async with oauth:
22-
url = await oauth.get_authorization_url()
22+
url = await oauth.login_url()
2323
return RedirectResponse(url=url)
2424

2525

2626
@app.get("/callback")
27-
async def oauth_callback(callback: Annotated[OAuth2Callback, Depends()]) -> OpenID:
27+
async def callback(call: Annotated[OAuth2Callback, Depends()]) -> OpenID:
2828
async with oauth:
29-
await oauth.authorize(callback)
30-
return await oauth.userinfo()
29+
return await oauth.callback(call)

fastlink/__init__.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from fastlink.client.httpx import HttpxClient
2-
from fastlink.google.client import GoogleOAuth
3-
from fastlink.telegram.auth import TelegramAuth
4-
from fastlink.yandex.client import YandexOAuth
1+
from fastlink.base.client import FastLink
2+
from fastlink.google.provider import GoogleSSO
3+
from fastlink.telegram.provider import TelegramSSO
4+
from fastlink.yandex.provider import YandexSSO
55

66
__all__ = [
7-
"GoogleOAuth",
8-
"HttpxClient",
9-
"TelegramAuth",
10-
"YandexOAuth",
7+
"FastLink",
8+
"GoogleSSO",
9+
"TelegramSSO",
10+
"YandexSSO",
1111
]

0 commit comments

Comments
 (0)