Options
All
  • Public
  • Public/Protected
  • All
Menu

Authentication-related utilities for use with Twilio Functions.

Index

Type aliases

AuthEnvVars

AuthEnvVars: { AUTH_PASSCODE: string; AUTH_USERNAME: string }

A type representing the environment variables used by the isAuthenticated function. Can be used as a type variable for a Function's Context type, IE: Context<AuthEnvVars>.

Type declaration

  • AUTH_PASSCODE: string
  • AUTH_USERNAME: string

AuthEvent

AuthEvent: { request: { headers: { authorization: string } } }

A Serverless Event with headers representing authentication data.

Type declaration

  • request: { headers: { authorization: string } }
    • headers: { authorization: string }
      • authorization: string

Functions

isAuthenticated

  • Uses Twilio Functions' support for the HTTP authorization header to check if an incoming request is authenticated.

    This function expects the environment variables in AuthEnvVars to be defined in the calling Function's environment.

    Note that isAuthenticated currently only works for one pre-defined username and passcode.

    Usage:

    if (!isAuthenticated(context, event)) {
    return callback(null, 'Invalid credentials');
    }

    Parameters

    • context: Context<AuthEnvVars>

      A Serverless Context containing authentication environment variables.

    • event: AuthEvent

      An incoming Serverless request.

    Returns boolean

    true if the incoming request's credentials match those given in the Function's environment variables. false otherwise.

Generated using TypeDoc