Orchard Core X Twitter Integration
The X Twitter module has two distinct features. OrchardCore.Twitter configures
the API client and workflow status activity. OrchardCore.Twitter.Signin
depends on it and OrchardCore.Users.ExternalAuthentication to add external
sign-in. Configure API credentials with the minimum provider permissions
required for the selected capability.
Guidelines
- Enable
OrchardCore.Twitterfor the API client and status-update workflow task. - Enable
OrchardCore.Twitter.Signinonly when X external login is required. - Enable Users registration separately when external identities may create new local users.
- Store consumer secrets and access-token secrets in secure configuration.
TwitterClientis registered throughAddHttpClientwith bounded retry behavior.UpdateTwitterStatusTaskreturnsDoneorFailedand stores the response inTwitterResponse.- Use the feature’s admin settings,
ConfigureTwitterSettings(), orITwitterSettingsServicefor tenant credentials. - Sign in with X reuses the API
ConsumerKeyandConsumerSecret; its own settings only holdCallbackPathandSaveTokens. - Do not log provider credentials or raw failure response content in production.
- All recipe JSON uses the root
{ "steps": [...] }format.
Enable X Integration
{
"steps": [
{
"name": "Feature",
"enable": [
"OrchardCore.Twitter"
],
"disable": []
}
]
}
For sign-in, add OrchardCore.Twitter.Signin:
{
"steps": [
{
"name": "Feature",
"enable": [
"OrchardCore.Twitter",
"OrchardCore.Twitter.Signin"
],
"disable": []
}
]
}
Configure API Credentials
Configure them at Settings → Integrations → X (Twitter). TwitterSettings contains the OAuth credentials used by TwitterClient:
| Property | Purpose |
|---|---|
| ConsumerKey | Application consumer key. |
| ConsumerSecret | Application consumer secret. |
| AccessToken | Account access token for API operations. |
| AccessTokenSecret | Account access-token secret. |
| ConsumerSecretSecretName, AccessTokenSecretSecretName | 4.0. Names of TextSecret entries of the Secrets module; each takes precedence over its protected value. |
With the OrchardCore.Secrets feature enabled, both secret editors offer
Use a secret (suggested names Twitter.ConsumerSecret and
Twitter.AccessTokenSecret), and saved values can be moved without retyping
them from Tools → Security → Migrate Secrets. The generic Settings step
can set the two *SecretName properties in TwitterSettings after a
Secrets step created the secrets; the TwitterSettings step has no
secret-name properties. See orchardcore-secrets.
The recipe step name is TwitterSettings (the generic Settings step with a
TwitterSettings object works too). The client decrypts the stored secrets
with data protection, as saved from the admin page, so secrets imported by a
recipe are stored as is and fail to decrypt. Prefer the admin page or
configuration for ConsumerSecret and AccessTokenSecret; the step replaces
all four values, so re-running it clears secrets entered earlier.
{
"steps": [
{
"name": "TwitterSettings",
"ConsumerKey": "consumer-key",
"AccessToken": "access-token"
}
]
}
For configuration overrides, call ConfigureTwitterSettings() on the
OrchardCoreBuilder and use the OrchardCore:X section:
builder.Services
.AddOrchardCms()
.ConfigureTwitterSettings();
{
"OrchardCore": {
"X": {
"ConsumerKey": "consumer-key",
"ConsumerSecret": "plain-consumer-secret",
"AccessToken": "access-token",
"AccessTokenSecret": "plain-access-token-secret"
}
}
}
ConsumerSecret and AccessTokenSecret are plain values here (for example
from OrchardCore__X__ConsumerSecret environment variables or a key vault);
Orchard Core protects them before use. In 4.0 they log a
LegacySecretConfiguration warning (event 8100); move them to secrets.
Sign In With X
Configure Settings → Security → Authentication → Sign In with X (Twitter).
The sign-in settings model exposes CallbackPath and SaveTokens; the
consumer key and secret come from the API settings above. Set CallbackPath
explicitly (for example /signin-x) and register the same full tenant URL as
the X app's callback URL. The sign-in startup registers
the authentication and provider-specific options configurations plus the
external login display driver.
Update X Status in a Workflow
Enable OrchardCore.Workflows in addition to OrchardCore.Twitter. The module
registers Update X (Twitter) Status Task. Its StatusTemplate is evaluated
through the workflow expression evaluator before TwitterClient.UpdateStatus
is called.
{
"steps": [
{
"name": "Feature",
"enable": [
"OrchardCore.Twitter",
"OrchardCore.Workflows"
],
"disable": []
}
]
}
Branch on Failed and avoid blindly retrying status updates in a workflow,
because a request may have reached the provider even if the response was lost.
Use TwitterClient Programmatically
Inject the registered typed client rather than creating an unauthenticated
HttpClient:
using OrchardCore.Twitter.Services;
namespace MyModule;
public sealed class SocialUpdateService
{
private readonly TwitterClient _twitterClient;
public SocialUpdateService(TwitterClient twitterClient)
{
_twitterClient = twitterClient;
}
public Task<HttpResponseMessage> PublishAsync(string status)
{
return _twitterClient.UpdateStatus(status);
}
}
Check the response status before reporting success and respect X platform
limits and policies.
Upgrading from 3.x
- Rename the
OrchardCore_XorOrchardCore_Twitterconfiguration section toOrchardCore:X(old names still work but are deprecated). - Plain
ConsumerSecretandAccessTokenSecretvalues from configuration are now honored; in 3.x they had to be already protected and were otherwise ignored. TwitterClientno longer fails after its first request; it no longer overwrites the shared settings' encrypted secrets with decrypted values.- Saved secrets keep working. Code reading
TwitterSettings.ConsumerSecretorAccessTokenSecretdirectly must also honorConsumerSecretSecretNameandAccessTokenSecretSecretName.