Get Credentials from Connection Parameters
The getCredentialsFromConnectionParameters method transforms user-provided connection parameters into the credential format required for authentication.
This method is useful when the format of credentials needed by the authentication mechanism differs from what users provide during connection setup or when you need to make additional requests to get/refresh credentials.
When using this method, you almost always should define the structure of the credentials this method returns in the customCredentialsSchema field of the connector definition.
Implementation
This method is implemented in JavaScript:
# Connector definition: Exchange user-provided email/password for an API access token
getCredentialsFromConnectionParameters:
type: javascript
code: |
export default async function getCredentialsFromConnectionParameters({
connectionInput,
}) {
const { email, password } = connectionInput
const response = await fetch('https://api.example.com/v1/get-token', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ email, password }),
})
const data = await response.json()
const accessToken = data?.access_token
if (!accessToken) {
throw new Error('Failed to get access token')
}
return { accessToken }
}Input
The method receives a context object with these properties:
| Property | Description |
|---|---|
connectionInput | Parameters provided by the user during connection setup. |
connectorParameters | Parameters configured for the connector in your workspace. |
Return Value
The method should return an object containing the credentials that will be added to the credentials stored in the Connection object.
Updated 2 days ago
