i2 Connect SDK
Search results for

    Show/hide table of contents

    Home > @i2analyze/i2connect > createAuthenticator

    createAuthenticator() function

    Creates an authenticator, which performs user authentication.

    Signature:

    export declare function createAuthenticator<TAuthForm extends services.AuthForm>(config: services.IAuthenticatorConfig<TAuthForm>, authenticate: (params: utility.AuthenticateCallbackParameters<TAuthForm>) => string | Promise<string>): services.IAuthenticator;
    

    Introduced: API version 2.0

    Type Parameters

    Parameter Type Description
    TAuthForm extends services.AuthForm The type of the authentication form.

    Parameters

    Parameter Type Description
    config services.IAuthenticatorConfig<TAuthForm> The authenticator configuration, which determines what users see when asked to authenticate.
    authenticate (params: utility.AuthenticateCallbackParameters<TAuthForm>) => string | Promise<string> The authentication callback.

    Returns:

    services.IAuthenticator

    The authenticator.

    Remarks

    You can use the created authenticator when you configure a service that requires authentication.

    Example

    const authenticator = createAuthenticator(
     {
       description: 'Please provide an API key',
       form: {
         apiKey: {
           label: 'API key',
           type: 'password',
         },
       },
     },
     ({ conditions: { apiKey } }) => {
       // In this example, we test whether the key matches "Example" and reject the request if it does not.
       if (apiKey !== 'Example') {
         throw new AuthenticationRequiredError({ title: 'Authentication failed' });
       }
    
       return 'Example authentication token';
     }
    );
    
    addService(
     {
       name: 'Sample',
       authenticator,
     },
     ({ authToken }) => {
       ...
     }
    );
    
    In this article
    Back to top © N. Harris Computer Corporation