sources/oauth: Fix an issue where wechat may crash duing login.#18973
sources/oauth: Fix an issue where wechat may crash duing login.#18973dewi-tik merged 7 commits intogoauthentik:mainfrom
Conversation
The WeChatOAuth2Client.get_access_token method was defined with a signature that required redirect_uri and code arguments, but the generic OAuth callback handler calls this method without any arguments (expecting the client to retrieve them from the request context). I have fixed authentik/sources/oauth/types/wechat.py by: Updating get_access_token signature: It now accepts **request_kwargs instead of mandatory positional arguments, matching the base OAuth2Client . Retrieving code correctly: It now looks for code in the request parameters using self.get_request_arg, just like standard OAuth clients. Adding State Validation: I added self.check_application_state() to ensure the state parameter matches, preventing CSRF attacks. Improving Error Handling: Both get_access_token and get_profile_info now return None (or error dicts) instead of raising exceptions when API calls fail. This prevents the "Server Error" (500) crashes you were seeing and allows Authentik to handle login failures gracefully. Signed-off-by: Anduin Xue <anduin@aiursoft.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #18973 +/- ##
==========================================
- Coverage 93.27% 93.21% -0.06%
==========================================
Files 967 967
Lines 53269 53282 +13
==========================================
- Hits 49684 49668 -16
- Misses 3585 3614 +29
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Signed-off-by: Anduin Xue <anduin@aiursoft.com>
Signed-off-by: Anduin Xue <anduin@aiursoft.com>
Signed-off-by: Anduin Xue <anduin@aiursoft.com>
✅ Deploy Preview for authentik-integrations ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-storybook ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for authentik-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
I have tested this via building locally and deployed at: https://auth.aiursoft.com/if/flow/aiursoft-authentication-flow/?next=%2F
I tested via clicking the WeChat icon and sign in with my personal wechat account. Everything went smooth right now.
@rissson Strongly recommand merging this before Authentik 12 release. Fixed critical issue that wechat login may crash after callback. |
* Fix an issue where wechat may crash duing login. The WeChatOAuth2Client.get_access_token method was defined with a signature that required redirect_uri and code arguments, but the generic OAuth callback handler calls this method without any arguments (expecting the client to retrieve them from the request context). I have fixed authentik/sources/oauth/types/wechat.py by: Updating get_access_token signature: It now accepts **request_kwargs instead of mandatory positional arguments, matching the base OAuth2Client . Retrieving code correctly: It now looks for code in the request parameters using self.get_request_arg, just like standard OAuth clients. Adding State Validation: I added self.check_application_state() to ensure the state parameter matches, preventing CSRF attacks. Improving Error Handling: Both get_access_token and get_profile_info now return None (or error dicts) instead of raising exceptions when API calls fail. This prevents the "Server Error" (500) crashes you were seeing and allows Authentik to handle login failures gracefully. Signed-off-by: Anduin Xue <anduin@aiursoft.com> * Update wechat.py Signed-off-by: Anduin Xue <anduin@aiursoft.com> * Update wechat.py Signed-off-by: Anduin Xue <anduin@aiursoft.com> * Remove unnecessary blank lines in wechat.py Signed-off-by: Anduin Xue <anduin@aiursoft.com> * Fix linting issues in wechat.py --------- Signed-off-by: Anduin Xue <anduin@aiursoft.com> Co-authored-by: Dewi Roberts <dewi@goauthentik.io>
|
🍒 Cherry-pick to |
…ry-pick #18973 to version-2025.12) (#19854) sources/oauth: Fix an issue where wechat may crash duing login. (#18973) * Fix an issue where wechat may crash duing login. The WeChatOAuth2Client.get_access_token method was defined with a signature that required redirect_uri and code arguments, but the generic OAuth callback handler calls this method without any arguments (expecting the client to retrieve them from the request context). I have fixed authentik/sources/oauth/types/wechat.py by: Updating get_access_token signature: It now accepts **request_kwargs instead of mandatory positional arguments, matching the base OAuth2Client . Retrieving code correctly: It now looks for code in the request parameters using self.get_request_arg, just like standard OAuth clients. Adding State Validation: I added self.check_application_state() to ensure the state parameter matches, preventing CSRF attacks. Improving Error Handling: Both get_access_token and get_profile_info now return None (or error dicts) instead of raising exceptions when API calls fail. This prevents the "Server Error" (500) crashes you were seeing and allows Authentik to handle login failures gracefully. * Update wechat.py * Update wechat.py * Remove unnecessary blank lines in wechat.py * Fix linting issues in wechat.py --------- Signed-off-by: Anduin Xue <anduin@aiursoft.com> Co-authored-by: Anduin Xue <anduin@aiursoft.com> Co-authored-by: Dewi Roberts <dewi@goauthentik.io>
* main: (52 commits) website: QL Search keyboard interactions docs, examples. (#16259) website/integrations: immich: add signing algorithm (#19187) website/docs: endpoint devices: add version command (#19767) common: introduce common (#19852) web: bump @sentry/browser from 10.37.0 to 10.38.0 in /web in the sentry group across 1 directory (#19871) core: bump debugpy from 1.8.19 to 1.8.20 (#19872) ci: bump actions/cache from 5.0.2 to 5.0.3 (#19873) web: bump chromedriver from 144.0.1 to 145.0.0 in /web (#19874) web: Captcha Refinements, Part 2 (#19757) root: assign cherry-pick PRs to original author (#19858) web: Lit Development Mode, performance fixes. (#19825) web: Fix development theme overrides (#19826) website/docs: add tip for recovering from accidental main branch work (#19865) web: bump API Client version (#19857) rbac: clean up roles and permissions (#19588) web: bump API Client version (#19851) website/docs: add more info to entra id scim doc (#19849) sources/oauth: Fix an issue where wechat may crash duing login. (#18973) providers/scim: fix email validation mismatch (#19848) providers/scim: modify user- and group syncing behavior (#13947) ...


The WeChatOAuth2Client.get_access_token method was defined with a signature that required redirect_uri and code arguments, but the generic OAuth callback handler calls this method without any arguments (expecting the client to retrieve them from the request context).
This is an issue with authentik 2025.12.0-rc1 and rc2.
I have fixed
authentik/sources/oauth/types/wechat.py
by:
Updating
get_access_token
signature: It now accepts **request_kwargs instead of mandatory positional arguments, matching the base
OAuth2Client
.
Retrieving code correctly: It now looks for code in the request parameters using self.get_request_arg, just like standard OAuth clients. Adding State Validation: I added self.check_application_state() to ensure the state
parameter matches, preventing CSRF attacks.
Improving Error Handling: Both
get_access_token
and
get_profile_info
now return None (or error dicts) instead of raising exceptions when API calls fail. This prevents the "Server Error" (500) crashes you were seeing and allows Authentik to handle login failures gracefully.
Checklist
ak test authentik/)make lint-fix)If an API change has been made
make gen-build)If changes to the frontend have been made
make web)If applicable
make docs)