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 auth spec.
Implementation
This method is implemented in JavaScript:
// File: auth/get-credentials-from-connection-parameters.js
import axios from 'axios'
export default async function getCredentialsFromConnectionParameters({
connectionParameters,
}) {
const { email, password } = connectionParameters
const res = await axios.post('https://api.example.com/v1/get-token', {
email,
password,
})
const accessToken = res.data?.access_token
if (!accessToken) {
throw new Error('Failed to get access token')
}
return { accessToken }
}
In your spec.yml:
auth:
# ...other auth settings
getCredentialsFromConnectionParameters:
implementationType: javascript
Input
The method receives a context object with these properties:
Property | Description |
---|---|
connectionParameters | 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 12 days ago