Follow these steps to configure Twitter for social login:
# OAuth Configuration
# Step 1: Create a new app
- Go to the Twitter Application Manager (opens new window).
- Click “Create New App” to create a new Twitter application.
- Fill all required fields.
- Go to Craft Control Panel → Settings → Social → Login Providers → Twitter and locate the Redirect URI.
- If the Redirect URI contains query parameters, change Craft’s usePathInfo (opens new window) config to
true
to usePATH_INFO
to specify the path as Twitter doesn’t allow query parameters in callback URLs (opens new window) anymore. - Copy the Redirect URI to the Twitter application’s “Callback URL” field.
- Agree to the terms and save the application.
# Step 2: Setup app permissions
- First, you need to contact Twitter to whitelist your app (opens new window) to be able to request a user’s email.
- Click “I need access to special permissions” and fill your application details.
- In Permissions Requested ask for the “email” special permission.
- Twitter will send you an email to confirm that you have email access (it usually takes less than 24 hours).
- Now go back to the Twitter Application manager and click on the app that you've just created to edit it.
- Under Permissions → Access, select “Read and write” (don’t choose the one that gives access to Direct Messages otherwise social login will fail).
- 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
- 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.
- 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 (opens new window) object.
# Properties
uid
nickname
name
firstName
lastName
email
location
description
imageUrl
urls
extra
# Methods
getIterator()
← Google Registration →