Authentication for feeds
Let your users authenticate their own partner account when they create a destination on your feed.
Your goal
Let your users connect their own partner account to your feed in self-service, by implementing the authentication flow behind a destination.
Expected outcome
A plugin version whose destinations authenticate from the interface: the credentials are validated by your plugin, stored in the platform vault, tested regularly, and reflected in the destination status.
Before you start
Your plugin version is the connector in the levels of activation. Each destination is an authenticated instance of it for one partner account, each destination carries presets, and each preset carries feeds.
Your feed has a layout: the authentication form is declared in it. See Layouts for feeds.
Turn authentication on
Each plugin version has an auth_flag boolean that controls whether authentication is managed by the plugin. It is set in Computing Console, on the plugin version configuration page.
auth_flag
Effect
true
The platform enforces the authentication flow, and the destination status follows it. The plugin must implement the methods of its authentication type.
false
Authentication is skipped. The destination status is set to Unknown, and no credential flow is triggered. Use it for connectors that do not require authentication.
Choose the authentication type
In Computing Console, on the plugin version configuration page, set the Authentication type field. It decides which fields the user sees when creating a destination, and which methods the platform calls. It defaults to No credentials, and once you set another type, it can no longer be changed.
Is redirected to the partner login page, through an OAuth 2.0 flow. A refresh token is stored in the platform vault.
OAuth2 (OAUTH2)
onCreateOAuthRedirectUrl, then onAuthentication, then onTestAuthentication.
Enters a single secret, an API token or an access key.
API token (API_TOKEN)
onAuthentication, then onTestAuthentication.
Enters a login and a password.
Login / Password (LOGIN_PASSWORD)
onAuthentication, then onTestAuthentication.
Nothing: the destination creation skips the authentication step.
No credentials (NO_CREDENTIALS)
None.
The authentication type sets the fields of the form: a button for OAUTH2, one token field for API_TOKEN, a login field and a password field for LOGIN_PASSWORD. The layout only sets their wording, see Declare the authentication form in the layout.
The methods each case requires:
onCreateOAuthRedirectUrl
Required
-
-
-
onAuthentication
Required
Required
Required
-
onTestAuthentication
Required
Required
Required
-
onLogout
Required
Optional
Optional
-
Declare the authentication form in the layout
The authentication type decides which fields the form shows. The authentication object of your layout sets their wording: the labels, the help texts and the OAuth 2.0 button. Without it, the form keeps its default wording.
With API_TOKEN, name the token field the way your partner names it:
With LOGIN_PASSWORD, word the two fields:
With OAUTH2, label the button that triggers the redirect, and give it an icon:
In the same layout file, group the plugin properties under the section matching the step where they are set, so the interface shows them at the right step:
Implement the authentication methods
The SDK routes every authentication call to these methods.
onCreateOAuthRedirectUrl
Called when the platform needs the OAuth 2.0 authorisation URL. The interface redirects the user to it, so they can grant access on the partner platform.
feed_destination_id
string
The ID of the destination, created as a draft before the OAuth flow starts. Must be embedded in the state parameter of the authorisation URL.
datamart_id
string
The datamart ID for the current context.
plugin_version_id
string
The plugin version ID.
login_url
string
The full OAuth 2.0 authorisation URL. Must include a state parameter containing feed_destination_id.
onAuthentication
Called after the user completes the authentication step: for OAuth 2.0, after the partner redirects back with the authorisation code; for a token or a login and password, after the user submits the form.
The plugin validates the credentials. When feed_destination_id is present in the request, it also returns them in the response, and the SDK stores them in the vault automatically.
feed_destination_id
string, optional
Present in the destination flow. When set, the SDK stores the credentials returned by this method in the vault.
params
Record<string, unknown>, optional
For OAuth 2.0, the redirected URL with the authorisation code. For a token or a login and password, the form field values.
datamart_id
string
The datamart ID.
plugin_version_id
string
The plugin version ID.
user_id
string
The user who triggered the authentication.
status
'ok' or 'error'
The result of the authentication attempt.
credentials
FeedDestinationCredentials, optional
Required when feed_destination_id is present: the credentials to store in the vault.
message
string, optional
A human-readable error message when status is 'error'.
onTestAuthentication
Called by the platform right after onAuthentication succeeds, then periodically, to keep destination statuses up to date. The SDK fetches the credentials from the vault and passes them as the second argument: the FeedDestinationCredentials object stored during onAuthentication.
feed_destination_id
string
The destination whose credentials are tested.
datamart_id
string
The datamart ID.
plugin_version_id
string
The plugin version ID.
Return status
HTTP code
When to use it
'ok'
200
The credentials are valid. The destination status becomes Authenticated.
'invalid_credentials'
401
The partner explicitly rejected the credentials, for instance a revoked token. The destination status becomes Error. Use it to tell credential rejection apart from operational failures.
'error'
500
An unexpected or operational error, such as a network failure or the partner API being down.
'not_implemented'
400
The method is not overridden. The default SDK behaviour.
Every status except 'ok' can carry an optional message for context.
onLogout
Called when the user removes the authentication from a destination. The plugin revokes the token on the partner side and cleans up any state it stored.
feed_destination_id
string, optional
The destination being logged out.
datamart_id
string
The datamart ID.
plugin_version_id
string
The plugin version ID.
user_id
string
The user triggering the logout.
status
'ok' or 'error'
The result of the logout.
message
string, optional
An error message when status is 'error'.
Use the credentials in the rest of the plugin
SDK helper methods
The base plugin class exposes helpers to manage credentials, callable from any method of your plugin.
fetchFeedDestinationCredentials(feedDestinationId)
Fetches the credentials stored in the vault for a destination. Throws a ResourceNotFoundError if none exist.
fetchFeedDestinationCredentialsOptional(feedDestinationId)
The same, but returns undefined instead of throwing when no credentials are found. Useful to fall back on credentials kept in a configuration file.
upsertFeedDestinationCredentials(feedDestinationId, credentials)
Creates or updates the credentials of a destination in the vault. The SDK calls it from onAuthentication in the standard flow: call it yourself only when managing credentials outside that flow.
In instanceContextBuilder
Since SDK v0.41.0, when a request carries a feed_destination_id, the SDK fetches the destination credentials from the vault and passes them as an optional second argument to instanceContextBuilder. Use them to initialise your partner client instead of reading a credential file:
The same credentials are also passed to onUserSegmentUpdate, onTroubleshoot and onDynamicPropertyValuesQuery.
Verify
Creating a destination on your feed shows the authentication form or the OAuth button you declared.
Once authentication is validated, the destination is created with the status Authenticated.
Credentials rejected by the partner move the destination to Error at the next test.
Removing the authentication from a destination revokes the token on the partner side.
Related pages
Last updated
Was this helpful?