Skip to content

Latest commit

 

History

History

basic-auth

Aligent CloudFront Authentication

  • Enforces Basic Authentication for CloudFront requests.
  • Simplified deployment using the BasicAuthFunction construct.
  • For usage in CDK projects or alongside Aligent CDK-Constructs

Components

  1. Lambda@Edge Handler: Implements the Basic Authentication logic.
  2. BasicAuthFunction Construct: A CDK construct for deploying the handler as a Lambda@Edge function.

Installation

Add the package to your CDK project: npm install @aligent/cdk-basic-auth

Example Usage

...
import { BasicAuthFunction, BasicAuthFunctionOptions } from 'your-package-name';
...

export class StaticHostingStack extends Stack {
  constructor(scope: Construct, id: string, props: StaticHostingProps) {
    super(scope, id, props);
    const basicAuthFunction = new BasicAuthFunction(this, 'MyBasicAuthFunction', { username: 'testuser', password: 'password' });
    const defaultBehaviorEdgeLambdas: EdgeLambda[] = [];
      defaultBehaviorEdgeLambdas.push(
        {
          eventType: LambdaEdgeEventType.ORIGIN_REQUEST,
          functionVersion: basicAuthFunction.edgeFunction.currentVersion
        }
      );
    }
...

This is a basic non-functional implementation. See StaticHosting/README.md to cover full usage.

Error Handling

  • Invalid Credentials: Responds with 401 Unauthorized.
  • Missing Credentials: Responds with 401 Unauthorized and prompts for Basic Authentication.