6.2.0 • Published 4 months ago

@educandu/rooms-auth-lambda v6.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

rooms-auth-lambda

codecov

Lambda@Edge function for authorizing access to private room resources in educandu.

Prerequisites

  • node.js ^18.0.0
  • optional: globally installed gulp: npm i -g gulp-cli

The output of this repository is an npm package (@educandu/rooms-auth-lambda) as well as a zip file containing the Lambda@Edge function.

Usage

The handler in this package is supposed to run as a Lambda@Edge function in AWS.

Environment variables

export SESSION_COOKIE_NAME="SESSION_ID" # mandatory
export WEBSITE_BASE_URL="https://consuming-website.com" # mandatory
export X_ROOMS_AUTH_SECRET="<secret>" # mandatory
export DISABLE_LOGGING="true" # optional, defaults to logging being enabled

As AWS Lambda@Edge function do not support environment variables, any values have to be injected into the code itself after deployment, for example at the top of the bundle file:

process.env.SESSION_COOKIE_NAME = 'SESSION_ID';
process.env.WEBSITE_BASE_URL = 'https://consuming-website.com';
process.env.X_ROOMS_AUTH_SECRET = "<secret>"

In AWS as a Lambda@Edge function

Run gulp build and you will find a single script file index.js in the dist folder which contains a bundle of all code needed to run on AWS. You will also find a file lambda.zip in the pack folder containing the bundle. This can be used for automated deployments on AWS (The Github action publish creates a release on Github and uploads this zip file).

In code as a node module

yarn add @educandu/rooms-auth-lambda --dev
import { handler } from '@educandu/rooms-auth-lambda';

handler(event, context, (error, result) => {
  // Do something
});

Development Server

This package comes with a development server that can be used for testing the lambda locally. The server object returned by the call is the object you would get when starting an express server.

In code as a node module

yarn add @educandu/rooms-auth-lambda --dev

export SESSION_COOKIE_NAME="SESSION_ID"
export WEBSITE_BASE_URL="http://localhost:3000"
export X_ROOMS_AUTH_SECRET="<secret>"
import { startDevServer } from '@educandu/rooms-auth-lambda';

const port = 10000;
const cdnBaseUrl = 'http://localhost:9000/my-bucket';

const server = startDevServer(cdnBaseUrl, port, err => {
  // Do something with err
});

// Then, in the end, close the server:
server.close(err => {
  // Do something with err
});

As a stand-alone node process

yarn add @educandu/rooms-auth-lambda --dev

export PORT=10000
export CDN_BASE_URL="http://localhost:9000/my-bucket"

export SESSION_COOKIE_NAME="SESSION_ID"
export WEBSITE_BASE_URL="http://localhost:3000"
export X_ROOMS_AUTH_SECRET="<secret>"

node ./node_modules/@educandu/rooms-auth-lambda/src/dev-server/run.js

OER learning platform for music

Funded by 'Stiftung Innovation in der Hochschullehre'

A Project of the 'Hochschule für Musik und Theater München' (University for Music and Performing Arts)

Project owner: Hochschule für Musik und Theater München\ Project management: Ulrich Kaiser

6.2.0

4 months ago

6.1.0

5 months ago

6.0.1

6 months ago

6.0.0

6 months ago

5.0.1

1 year ago

3.0.1

1 year ago

5.0.0

1 year ago

3.0.0

1 year ago

2.0.3

1 year ago

2.0.2

1 year ago

2.0.4

1 year ago

4.0.1

1 year ago

4.0.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago