Interface ApiTokenAuthDefinitionInput<Credential, UserInputsSchema>

interface ApiTokenAuthDefinitionInput {
    getCredentialDataFromUserInputs: ((opts) => Credential["data"] | Promise<Credential["data"]>);
    getCredentialOption: GetCredentialOptionFn<Credential>;
    refreshTokens?: ((opts) => Credential["data"] | Promise<Credential["data"]>);
    singleCredentialOnly?: boolean;
    testConnection: ((opts) => Promise<boolean>);
    userInputsSchema: UserInputsSchema;
}

Type Parameters

  • Credential extends AnyAppCredential

  • UserInputsSchema extends AuthUserInputDefinition[]

Properties

getCredentialDataFromUserInputs: ((opts) => Credential["data"] | Promise<Credential["data"]>)

Type declaration

    • (opts): Credential["data"] | Promise<Credential["data"]>
    • Receives the field values defined by userInputsSchema and should return the credential data

      Parameters

      • opts: {
            httpRequest: {
                ipAddress: null | string;
                userAgent: string;
            };
            userInputs: InferAuthUserInputsType<UserInputsSchema>;
        }
        • httpRequest: {
              ipAddress: null | string;
              userAgent: string;
          }
          • ipAddress: null | string
          • userAgent: string
        • userInputs: InferAuthUserInputsType<UserInputsSchema>

      Returns Credential["data"] | Promise<Credential["data"]>

getCredentialOption: GetCredentialOptionFn<Credential>

Receives a Credential and should return the avatar and label for this credential. It's called every time a credential is rendered in UI.

refreshTokens?: ((opts) => Credential["data"] | Promise<Credential["data"]>)

Type declaration

    • (opts): Credential["data"] | Promise<Credential["data"]>
    • Receives the credential, should refresh it if needed and return new credential data.

      Parameters

      • opts: {
            consumer: Consumer;
            credential: Credential;
        }
        • consumer: Consumer
        • credential: Credential

      Returns Credential["data"] | Promise<Credential["data"]>

singleCredentialOnly?: boolean

If true, it's assumed there will be always one credential only at most, therefore UI for selecting credential won't not rendered.

Default

false
testConnection: ((opts) => Promise<boolean>)

Type declaration

    • (opts): Promise<boolean>
    • Receives Credential data, as specified by Credential type and should return true/false depending on whether the credential works.

      Parameters

      • opts: {
            httpRequest: {
                ipAddress: null | string;
                userAgent: string;
            };
            userInputs: InferAuthUserInputsType<UserInputsSchema>;
        }
        • httpRequest: {
              ipAddress: null | string;
              userAgent: string;
          }
          • ipAddress: null | string
          • userAgent: string
        • userInputs: InferAuthUserInputsType<UserInputsSchema>

      Returns Promise<boolean>

userInputsSchema: UserInputsSchema

List of inputs to render when adding a new credential in UI.