-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
sources/oauth/twitter: update fields, scopes and profile URL to match current X API #18670
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,11 +15,18 @@ class TwitterOAuthRedirect(OAuthRedirect): | |
| """Twitter OAuth2 Redirect""" | ||
|
|
||
| def get_additional_parameters(self, source): # pragma: no cover | ||
| scopes = ["users.read", "tweet.read"] | ||
| # If admin has defined custom scopes in the provider UI, merge them | ||
| configured = getattr(source, "scope", []) or [] | ||
| for s in configured: | ||
| if s not in scopes: | ||
| scopes.append(s) | ||
| return { | ||
| "scope": ["users.read", "tweet.read"], | ||
| "scope": scopes, | ||
| } | ||
|
|
||
|
|
||
|
|
||
| class TwitterOAuthCallback(OAuthCallback): | ||
| """Twitter OAuth2 Callback""" | ||
|
|
||
|
|
@@ -40,13 +47,20 @@ class TwitterType(SourceType): | |
|
|
||
| authorization_url = "https://twitter.com/i/oauth2/authorize" | ||
| access_token_url = "https://api.twitter.com/2/oauth2/token" # nosec | ||
| profile_url = "https://api.twitter.com/2/users/me" | ||
| profile_url = "https://api.twitter.com/2/users/me?user.fields=verified,username,name,profile_image_url,confirmed_email" | ||
|
||
|
|
||
| pkce = PKCEMethod.S256 | ||
|
|
||
| def get_base_user_properties(self, info: dict[str, Any], **kwargs) -> dict[str, Any]: | ||
| data = info.get("data", {}) | ||
| email = ( | ||
| data.get("confirmed_email") | ||
| or data.get("email") | ||
|
||
| or None | ||
| ) | ||
| return { | ||
| "username": data.get("username"), | ||
| "email": None, | ||
| "email": email, | ||
| "name": data.get("name"), | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to this doc, to get the email, we must add the following scope:
users.email