providers/twitter
default()β
default(
config
):OAuthConfig
<TwitterProfile
>
Add Twitter login to your page.
Setupβ
Callback URLβ
https://example.com/api/auth/callback/twitter
Configurationβ
import Auth from "@auth/core"
import Twitter from "@auth/core/providers/twitter"
const request = new Request(origin)
const response = await Auth(request, {
providers: [Twitter({ clientId: TWITTER_CLIENT_ID, clientSecret: TWITTER_CLIENT_SECRET })],
})
Resourcesβ
OAuth 2β
Twitter supports OAuth 2, which is currently opt-in. To enable it, simply add version: "2.0" to your Provider configuration:
TwitterProvider({
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.
Email is currently not supported by Twitter OAuth 2.0.
Notesβ
Twitter is currently the only built-in provider using the OAuth 1.0 spec.
This means that you won't receive an access_token
or refresh_token
, but an oauth_token
and oauth_token_secret
respectively. Remember to add these to your database schema, in case if you are using an Adapter.
You must enable the "Request email address from users" option in your app permissions if you want to obtain the users email address.
By default, Auth.js assumes that the Twitter provider is based on the OAuth 2 specification.
The Twitter provider comes with a default configuration. To override the defaults for your use case, check out customizing a built-in OAuth provider.
If you think you found a bug in the default configuration, you can open an issue.
Auth.js strictly adheres to the specification and it cannot take responsibility for any deviation from the spec by the provider. You can open an issue, but if the problem is non-compliance with the spec, we might not pursue a resolution. You can ask for more help in Discussions.
Parametersβ
βͺ config: OAuthUserConfig
<TwitterProfile
>
Returnsβ
OAuthConfig
<TwitterProfile
>