Skip to content

sources/oauth: Fix an issue where wechat may crash duing login.#18973

Merged
dewi-tik merged 7 commits intogoauthentik:mainfrom
Anduin2017:patch-4
Jan 29, 2026
Merged

sources/oauth: Fix an issue where wechat may crash duing login.#18973
dewi-tik merged 7 commits intogoauthentik:mainfrom
Anduin2017:patch-4

Conversation

@Anduin2017
Copy link
Contributor

@Anduin2017 Anduin2017 commented Dec 20, 2025

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

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema has been updated (make gen-build)

If changes to the frontend have been made

  • The code has been formatted (make web)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make docs)

 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>
@Anduin2017 Anduin2017 requested a review from a team as a code owner December 20, 2025 06:22
@codecov
Copy link

codecov bot commented Dec 20, 2025

Codecov Report

❌ Patch coverage is 26.08696% with 17 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.21%. Comparing base (6ca26b5) to head (91e52e3).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
authentik/sources/oauth/types/wechat.py 26.08% 17 Missing ⚠️
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     
Flag Coverage Δ
conformance 38.08% <26.08%> (-0.01%) ⬇️
e2e 44.08% <26.08%> (-0.01%) ⬇️
integration 22.88% <26.08%> (-0.05%) ⬇️
unit 91.39% <26.08%> (-0.04%) ⬇️
unit-migrate 91.43% <26.08%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Anduin Xue <anduin@aiursoft.com>
Signed-off-by: Anduin Xue <anduin@aiursoft.com>
Signed-off-by: Anduin Xue <anduin@aiursoft.com>
@netlify
Copy link

netlify bot commented Dec 23, 2025

Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit ab705d9
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/694a8217d0850100081d4b1a
😎 Deploy Preview https://deploy-preview-18973--authentik-integrations.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Dec 23, 2025

Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit ab705d9
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/694a8217ee52370008d644be
😎 Deploy Preview https://deploy-preview-18973--authentik-storybook.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Dec 23, 2025

Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit ab705d9
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/694a82175f9b610008f24e87
😎 Deploy Preview https://deploy-preview-18973--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@Anduin2017
Copy link
Contributor Author

I have tested this via building locally and deployed at:

https://auth.aiursoft.com/if/flow/aiursoft-authentication-flow/?next=%2F

image

I tested via clicking the WeChat icon and sign in with my personal wechat account. Everything went smooth right now.

image

@rissson Strongly recommand merging this before Authentik 12 release. Fixed critical issue that wechat login may crash after callback.

@Anduin2017
Copy link
Contributor Author

@rissson

@BeryJu BeryJu changed the title Fix an issue where wechat may crash duing login. sources/oauth: Fix an issue where wechat may crash duing login. Jan 15, 2026
@BeryJu BeryJu added area:backend backport/version-2025.12 Add this label to PRs to backport changes to version-2025.12 labels Jan 15, 2026
@dewi-tik dewi-tik self-assigned this Jan 22, 2026
@dewi-tik dewi-tik enabled auto-merge (squash) January 29, 2026 16:22
@dewi-tik dewi-tik merged commit e01d7f2 into goauthentik:main Jan 29, 2026
99 of 100 checks passed
authentik-automation bot pushed a commit that referenced this pull request Jan 29, 2026
* 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>
@authentik-automation
Copy link
Contributor

🍒 Cherry-pick to version-2025.12 created: #19854

dewi-tik added a commit that referenced this pull request Jan 29, 2026
…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>
kensternberg-authentik added a commit that referenced this pull request Jan 31, 2026
* 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)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:backend backport/version-2025.12 Add this label to PRs to backport changes to version-2025.12

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants