flet
flet copied to clipboard
feat: Add WeChat oauth provider
Description
Added WeChat OAuth Provider by extending the existing OAuthToken class to include WeChat-specific fields openid and unionid, also modify Authorization class to adapt WeChat OAuth flow.
Test Code
import flet as ft
from flet.auth.provider import WeChatOAuthProvider
def main(page: ft.Page):
provider = WeChatOAuthProvider(
client_id="test_client_id",
client_secret="test_client_secret",
redirect_url="http://localhost:8550/oauth_callback",
)
def login_click(e):
page.login(provider)
def on_login(e):
print("Login error:", e.error)
print("Access token:", page.auth.token.access_token)
print("User ID:", page.auth.user.id)
page.on_login = on_login
page.add(ft.ElevatedButton("Login with GitHub", on_click=login_click))
ft.app(main, port=8550, view=ft.AppView.WEB_BROWSER)
Type of change
- [x] New feature (non-breaking change which adds functionality)
Checklist:
- [x] I signed the CLA.
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [x] I have commented my code, particularly in hard-to-understand areas
- [x] My changes generate no new warnings
- [x] New and existing tests pass locally with my changes
Screenshots (if applicable):
Additional details
Summary by Sourcery
Add support for WeChat as an OAuth provider by implementing a new WeChatOAuthProvider class and extending the OAuthToken class to handle WeChat-specific fields. Update the Authorization class to integrate the WeChat OAuth flow, ensuring proper token and user data management.
New Features:
- Introduce a new WeChat OAuth provider by extending the existing OAuthToken class to support WeChat-specific fields such as
openidandunionid.
Enhancements:
- Modify the Authorization class to accommodate the WeChat OAuth flow, including changes to request token handling and user information retrieval.
Reviewer's Guide by Sourcery
This pull request adds WeChat OAuth provider support to the Flet authentication system. The implementation extends the existing OAuth functionality to accommodate WeChat's specific OAuth flow, which differs from standard implementations. Key changes include modifying the Authorization class, creating a new WeChatOAuthToken class, and implementing a new WeChatOAuthProvider class.
Sequence Diagram
sequenceDiagram
participant User
participant App
participant WeChatOAuthProvider
participant WeChatAPI
User->>App: Initiate login
App->>WeChatOAuthProvider: Request authorization URL
WeChatOAuthProvider->>WeChatAPI: Generate authorization URL
WeChatAPI-->>User: Present QR code
User->>WeChatAPI: Scan QR code and authorize
WeChatAPI-->>App: Redirect with authorization code
App->>WeChatOAuthProvider: Request token
WeChatOAuthProvider->>WeChatAPI: Exchange code for token
WeChatAPI-->>WeChatOAuthProvider: Return token with openid
WeChatOAuthProvider->>WeChatAPI: Fetch user info
WeChatAPI-->>WeChatOAuthProvider: Return user details
WeChatOAuthProvider-->>App: Return authenticated user
File-Level Changes
| Change | Details | Files |
|---|---|---|
| Extend OAuthToken class to support WeChat-specific fields |
|
sdk/python/packages/flet-runtime/src/flet_runtime/auth/oauth_token.py |
| Modify Authorization class to handle WeChat OAuth flow |
|
sdk/python/packages/flet-runtime/src/flet_runtime/auth/authorization.py |
| Implement WeChatOAuthProvider class |
|
sdk/python/packages/flet-runtime/src/flet_runtime/auth/providers/wechat_oauth_provider.py |
Tips and commands
- Trigger a new Sourcery review by commenting
@sourcery-ai reviewon the pull request. - Continue your discussion with Sourcery by replying directly to review comments.
- You can change your review settings at any time by accessing your dashboard:
- Enable or disable the Sourcery-generated pull request summary or reviewer's guide;
- Change the review language;
- You can always contact us if you have any questions or feedback.
@pengwon Thank you for your contribution! Could you look into resolving conflicts in this PR please?
I will have a try. Thank you for your review.
At this time, we’re not accepting refactoring PRs, non-trivial changes, or new features for Flet v0.2x. Our focus is currently on preparing the upcoming “v1” release (in the v1 branch).
But if you'd like to adopt your PR for v1 branch that'd be awesome.