Twitter

Follow these steps to configure Twitter for social login:

OAuth Configuration

Step 1: Create a new app

  1. Go to the Twitter Application Manager.
  2. Click “Create New App” to create a new Twitter application.
  3. Fill all required fields.
  4. Fill the “Callback URL” field with the Redirect URI found in Craft Control Panel → Settings → Social → Login Providers → Twitter.
  5. Agree to the terms and save the application.

Step 2: Setup app permissions

  1. First, you need to contact Twitter to whitelist your app to be able to request a user’s email.
  2. Click “I need access to special permissions” and fill your application details.
  3. In Permissions Requested ask for the “email” special permission.
  4. Twitter will send you an email to confirm that you have email access (it usually takes less than 24 hours).
  5. Now go back to the Twitter Application manager and click on the app that you've just created to edit it.
  6. Under Permissions → Access, select “Read and write” (don’t choose the one that gives access to Direct Messages otherwise social login will fail).
  7. Under Permissions → Additional Permissions, check the Request email addresses from users box (this will only be visible once Twitter has whitelisted your app).

Step 3: OAuth settings in Craft

  1. Twitter will provide you a consumer key and a consumer secret for your application, copy them to Craft Control Panel → Settings → Social → Login Providers → Twitter → OAuth, and use them as client ID and client secret values.
  2. Go to Craft Control Panel → Settings → Social → Login Providers and enable Twitter.

🎉

Default User Field Mapping

The Twitter login provider defines the following user field mapping by default.

[
    'id' => '{{ profile.uid }}',
    'email' => '{{ profile.email }}',
    'username' => '{{ profile.email }}',
    'photo' => '{{ profile.imageUrl|replace("_normal.", ".") }}',
]

You can override and extend the default mapping using the loginProviders config.

Profile Object

The profile response for the Twitter login provider is an OAuth 1 User object.

Properties

  • uid
  • nickname
  • name
  • firstName
  • lastName
  • email
  • location
  • description
  • imageUrl
  • urls
  • extra

Methods

  • getIterator()