Function defineApiTokenAuth
- define
Api <Credential>(): (<const UserInputsSchema>(definition) => ApiTokenAuthDefinition<Credential, UserInputsSchema>)Token Auth Type Parameters
Credential extends AnyAppCredential
Returns (<const UserInputsSchema>(definition) => ApiTokenAuthDefinition<Credential, UserInputsSchema>)
- <const UserInputsSchema>(definition): ApiTokenAuthDefinition<Credential, UserInputsSchema>
Type Parameters
const UserInputsSchema extends ({
infoHTML?: string;
key: string;
label: string;
placeholder?: string;
type: "textfield";
} | {
domain?: string;
infoHTML?: string;
key: string;
label: string;
placeholder?: string;
type: "subdomain";
} | {
infoHTML?: string;
key: string;
label: string;
options: ({ name: string; id: string; })[];
placeholder?: string;
type: "dropdown";
})[]
Parameters
definition: ApiTokenAuthDefinitionInput<Credential, UserInputsSchema>
Returns ApiTokenAuthDefinition<Credential, UserInputsSchema>
See
Example
import { AppCredential, defineApiTokenAuth } from "@rollout/framework";
export type MyAppCredential = AppCredential<{
apiKey: string;
}>;
export const auth = defineApiTokenAuth<MyAppCredential>()({
userInputsSchema: [
{
type: "textfield",
key: "apiKey",
label: "API Key",
placeholder: "Enter your API key",
infoHTML:
"You can generate a token navigating to Settings > Integrations > API.",
},
],
getCredentialDataFromUserInputs({ userInputs }) {
return userInputs;
},
async getCredentialOption({ credential }) {
const { label, avatar } = await getUser(credential.data.apiKey);
return { label, avatar };
},
async testConnection(credentialData) {
try {
await getUser(credentialData.apiKey);
return true;
} catch (error) {
return false;
}
},
});
Used to define a Connector API Token Auth