- Ory Console
- Ory CLI
Follow these steps to add Twitter as a social sign-in provider to your project using the Ory Console:
- Go to Authentication → Social Sign-In in the Ory Console.
- Click the switch next to the Twitter logo to start the configuration.
- Copy the Redirect URI and save it for later use.
The default redirect URI for twitter is https://$PROJECT_SLUG.projects.oryapis.com/self-service/methods/oidc/callback/twitter
. Write it down for later use.
Next you will need to create a Twitter application and configure it to work with Ory. Here's how you can do that:
- Head over to the Twitter Developer Dashboard. You do not need a subscription to Twitter's premium APIs to use the social sign-in feature and can use the free tier ("Sign up for Free Account").
- Create a new Twitter v2 project:
- Choose a use case for your application. We use "Exploring the API" for this example:
- Choose a description:
- If prompted, choose "Create a new app":
- You will now receive an API key and API Key Secret. Copy these values and save them for later use:
- Go to the application settings and click on "Set up" under "User authentication settings":
- Select your app permissions, set "Type of App" to "Confidential Client". If you need to read email addresses toggle "Request email from users" on. Provide the Redirect URI you saved earlier here:
Twitter is now set up! Continue with the following steps in Ory Console or Ory CLI to complete the configuration:
- Ory Console
- Ory CLI
Copy the API Key and API Key Secret from the Twitter Developer Dashboard and paste them into the corresponding fields in the Ory Console.
In the Data Mapping field of the form in the Ory Console, add the following Jsonnet code snippet, which maps the desired claims to the Ory Identity schema:
local claims = std.extVar('claims');
{
identity: {
traits: {
// Twitter does not send the email when it is not verified:
//
// When set to true email will be returned in the user objects as a string. If the user does not have an email address on their account, or if the email address is not verified, null will be returned.
//
// There we can use the value provided by twitter without problem:
[if 'email' in claims then 'email' else null]: claims.email,
},
},
}dangerDon't save secrets such as API keys, credentials, or personal data directly in Jsonnet code snippets. Jsonnet code snippets used for data mapping aren't stored in an encrypted format in Ory Network.
Click Save Configuration.
local claims = std.extVar('claims');
{
identity: {
traits: {
// Twitter does not send the email when it is not verified:
//
// When set to true email will be returned in the user objects as a string. If the user does not have an email address on their account, or if the email address is not verified, null will be returned.
//
// There we can use the value provided by twitter without problem:
[if 'email' in claims then 'email' else null]: claims.email,
},
},
}
Don't save secrets such as API keys, credentials, or personal data directly in Jsonnet code snippets. Jsonnet code snippets used for data mapping aren't stored in an encrypted format in Ory Network.
Encode the Jsonnet snippet with Base64 or host it under an URL accessible to Ory Network.
cat your-data-mapping.jsonnet | base64
Download the Ory Identities config from your project and save it to a file:
## List all available projects
ory list projects
## Get config
ory get identity-config {project-id} --format yaml > identity-config-$project-id.yamlAdd the social sign-in provider configuration to the downloaded config. Add the Jsonnet snippet with mappings as a Base64 string or provide an URL to the file.
selfservice:
methods:
oidc:
config:
providers:
- id: twitter
label: Twitter
provider: twitter
client_id: .... # Replace this with the API Key
client_secret: .... # Replace this with the API Key Secret
mapper_url: "base64://{YOUR_BASE64_ENCODED_JSONNET_HERE}"
# Alternatively, use an URL:
# mapper_url: https://storage.googleapis.com/abc-cde-prd/9cac9717f007808bf17f22ce7f4295c739604b183f05ac4afb4
scope:
- email
enabled: trueUpdate the Ory Identities configuration using the file you worked with:
ory update identity-config {project-id} --file identity-config.yaml
Troubleshooting
When you add a social sign-in provider, you can encounter common problems such as:
- Redirect URI mismatch
- Redirect loops during registration
- Domain verification issues
To troubleshoot those issues, read Social sign-in troubleshooting.