Twitter API v2

Backend class

For Django, add this class path to AUTHENTICATION_BACKENDS. For other integrations, use the same class path in the framework-specific backend setting.

Backend name

Class path

twitter-oauth2

social_core.backends.twitter_oauth2.TwitterOAuth2

Twitter offers per application keys named Client ID and Client Secret. To enable Twitter these two keys are needed. Further documentation at Twitter development resources:

  • Register a new application at Twitter App Creation,

  • Fill Client ID and Client Secret values:

    SOCIAL_AUTH_TWITTER_OAUTH2_KEY = ''
    SOCIAL_AUTH_TWITTER_OAUTH2_SECRET = ''
    
  • You can specify PKCE challenge method following:

    SOCIAL_AUTH_TWITTER_OAUTH2_PKCE_CODE_CHALLENGE_METHOD = ''
    

    The possible values for configuration are s256 and plain. By default, s256 is set.

    You can see more information about PKCE at RFC7636.

  • You need to specify an URL callback or the OAuth will raise a “403 Client Error”. The callback URL should be something like “https://example.com/complete/twitter-oauth2