Skip to content

feat: update Twitter provider to retrieve email #12819

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 5 additions & 14 deletions packages/core/src/providers/twitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ export interface TwitterProfile {
id: string
/** The friendly name of this user, as shown on their profile. */
name: string
/** @note Email is currently unsupported by Twitter. */
email?: string
/** @note Twitter (X) only returns the email if is has been confirmed under the "confirmed_email" property. */
confirmed_email?: string
/** The Twitter handle (screen name) of this user. */
username: string
/**
Expand Down Expand Up @@ -133,22 +134,12 @@ export interface TwitterProfile {
* - [Twitter App documentation](https://developer.x.com/en/apps)
*
* ## OAuth 2
* Twitter supports OAuth 2, which is currently opt-in. To enable it, simply add version: "2.0" to your Provider configuration:
* ```ts
* Twitter({
* clientId: process.env.TWITTER_ID,
* clientSecret: process.env.TWITTER_SECRET,
* version: "2.0", // opt-in to Twitter OAuth 2.0
* })
* ```
* Keep in mind that although this change is easy, it changes how and with which of Twitter APIs you can interact with. Read the official Twitter OAuth 2 documentation for more details.
*
*
* :::note
*
* Email is currently not supported by Twitter OAuth 2.0.
*
* :::
*
* ### Notes
*
Expand Down Expand Up @@ -190,14 +181,14 @@ export default function Twitter(
type: "oauth",
checks: ["pkce", "state"],
authorization:
"https://x.com/i/oauth2/authorize?scope=users.read tweet.read offline.access",
"https://x.com/i/oauth2/authorize?scope=users.read users.email tweet.read offline.access",
token: "https://api.x.com/2/oauth2/token",
userinfo: "https://api.x.com/2/users/me?user.fields=profile_image_url",
userinfo: "https://api.x.com/2/users/me?user.fields=profile_image_url,confirmed_email",
profile({ data }) {
return {
id: data.id,
name: data.name,
email: data.email ?? null,
email: data.confirmed_email || data.email || null,
image: data.profile_image_url,
}
},
Expand Down
Loading