Skip to content

sources/oauth: support email retrieval for Twitter login - #20468

Merged
BeryJu merged 3 commits into
goauthentik:mainfrom
chandanshyam:feat/18466-twitter-oauth-fetch-user-email
Jul 14, 2026
Merged

BeryJu merged 3 commits into
goauthentik:mainfrom
chandanshyam:feat/18466-twitter-oauth-fetch-user-email

Conversation

@chandanshyam

Copy link
Copy Markdown

This PR adds support for retrieving a user’s email address during the Twitter OAuth flow.

  • Include the users.email scope in the Twitter OAuth authorization request
  • Update the profile API call to request the confirmed_email field
  • Extract and populate the email in get_base_user_properties() from the Twitter profile response
  • Add test coverage for both cases: when a confirmed email is present and when it is not

Fixes #18466

Test Plan

  • Run Twitter OAuth source tests: uv run coverage run manage.py test authentik.sources.oauth.tests.test_type_twitter --keepdb
  • Verify tests pass for users without email
  • Verify tests pass for users with confirmed email
  • Test OAuth flow with Twitter source in development
    environment
  • Confirm email is properly fetched and saved when user has
    confirmed email on Twitter

I can even update the test_enroll_context with the email field instead of creating a new test as per comments/preference

Add the users.email scope to the Twitter OAuth request so we can access user email addresses.
Update the profile API call to include the confirmed_email field and extract it from the user properties.
Also add a test case to cover enrollment context when email data is present.

This enables email retrieval as part of the Twitter OAuth authentication flow.
Copilot AI review requested due to automatic review settings February 23, 2026 07:08
@chandanshyam
chandanshyam requested a review from a team as a code owner February 23, 2026 07:08
@netlify

netlify Bot commented Feb 23, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 2c6e73f
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a5629bc926ee200087fa6a4
😎 Deploy Preview https://deploy-preview-20468--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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR implements email retrieval support for the Twitter OAuth provider by adding the necessary scope, updating the API request to include email fields, and extracting the email from the response. The changes align with Twitter's OAuth 2.0 API v2 support for email address retrieval.

Changes:

  • Added users.email scope to Twitter OAuth authorization requests
  • Updated profile URL to request the confirmed_email field from Twitter's API
  • Modified email extraction logic to populate email from Twitter's response instead of hardcoding to None
  • Added test coverage for both scenarios: users with and without confirmed email

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
authentik/sources/oauth/types/twitter.py Added email scope to authorization, updated profile URL query parameters, and changed email extraction to use confirmed_email field
authentik/sources/oauth/tests/test_type_twitter.py Added test data and test case for Twitter users with confirmed email

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chandanshyam chandanshyam changed the title feat(sources/oauth): support email retrieval for Twitter login sources: oauth : support email retrieval for Twitter login Feb 23, 2026
@chandanshyam chandanshyam changed the title sources: oauth : support email retrieval for Twitter login sources/oauth : support email retrieval for Twitter login Feb 23, 2026
@BeryJu BeryJu changed the title sources/oauth : support email retrieval for Twitter login sources/oauth: support email retrieval for Twitter login Jul 14, 2026
Co-authored-by: Copilot <[email protected]>
Signed-off-by: Jens L. <[email protected]>
@netlify

netlify Bot commented Jul 14, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit 2c6e73f
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a5629bc48357e00085da28e
😎 Deploy Preview https://deploy-preview-20468--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

netlify Bot commented Jul 14, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 2c6e73f
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a5629bc926ee200087fa6a2
😎 Deploy Preview https://deploy-preview-20468--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.

@codecov

codecov Bot commented Jul 14, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.09%. Comparing base (fd0aa00) to head (a7f7e14).

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #20468      +/-   ##
==========================================
- Coverage   93.28%   93.09%   -0.19%     
==========================================
  Files        1045     1045              
  Lines       61348    61354       +6     
  Branches      424      424              
==========================================
- Hits        57227    57118     -109     
- Misses       4121     4236     +115     
Flag Coverage Δ
conformance 36.15% <12.50%> (-0.01%) ⬇️
e2e 40.76% <12.50%> (-0.56%) ⬇️
integration 32.08% <12.50%> (-0.50%) ⬇️
rust 0.00% <ø> (ø)
unit 92.38% <100.00%> (+<0.01%) ⬆️
unit-migrate 92.42% <100.00%> (-0.01%) ⬇️

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

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

@BeryJu
BeryJu merged commit 687cdf9 into goauthentik:main Jul 14, 2026
105 of 116 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve Twitter/X OAuth provider to support fetching user email in the X API v2

3 participants