Git Product home page Git Product logo

cvs-svc-authoriser's Introduction

cvs-svc-authoriser

Custom authentication and authorisation mechanism for all CVS API Gateway calls.

Documentation

See the Lambda Authorizer Confluence page.

Configuration

  • Configuration is a TS object of type AuthorizerConfig.
  • Both AuthorizerConfig and the configuration itself are in configuration.ts.
  • A (fake) example can be found here.

Prerequisites

Node JS

Check you have Node and NPM in your terminal:

node --version
npm --version

We strongly recommend nvm to manage your Node installations (nvm-windows on Windows). The project's .nvmrc (root directory) contains the recommended Node version.

To install on Linux:

sudo apt install nodejs

To install on MacOS, either:

To install on Windows, either:

Dependencies

npm install

Note the project's .npmrc intentionally specifies save-exact. This means dependencies at runtime will be locked to the specific version present in package.json.

Environment variables

This project does not have a .env file. Environment variables are not needed for local development, including for running tests. If this changes in future, please update this documentation.

Policy documents (authorizer return values) use four environment variables:

Environment variable Default
AWS_REGION eu-west-1
AWS_ACCOUNT_ID *
AWS_APIG_ID *
AWS_APIG_STAGE *

Currently, none of these are explicitly set by Terraform, so the default values are important.

In addition, all Terraform'd Lambda functions in DVSA share three environment variables:

  • BRANCH, currently set in package.json scripts. Doesn't make a difference when running locally.
  • BUCKET, unused.
  • SECRET_NAME, unused.

Build

npm run build

Output folder: build/ (Git-ignored)

On Windows, you will need to use Git Bash. You may also need to:

  • replace export statements with your own environment variable configuration.
  • find binaries for things like cpio.

Test

npm test

This project only contains unit tests. For integration tests, see cvs-svc-auto.

Local Invocation

The serverless-offline package is used to run the lambda locally. A test function is initialiased and protected by the lambda authoriser. Details of the configuration are in the serverless.yml file. Before running/debugging, copy the .env.example file to .env.

  • AZURE_CLIENT_ID needs to be a list of audiences the tokens will be validated against.
  • AZURE_TENANT_ID needs to be the tenantId to use for the token validation.

Running

Run npm start to run the test function and lambda authoriser. Once running, the test function can be called using postman or something similar. An example postman collection can be found at tests/resources/authoriser.postman_collection.json. There are a number of variables that need population before it will work. These are the details of credentials you will want to test i.e. clientId, secret etc. If there is any reason the token does not allow access to the resource the reason is sent back in the response.

{
  "statusCode": 403,
  "error": "Forbidden",
  "message": "User is not authorized to access this resource"
}

If the token does allow access, the request will be allowed through to the test function and "Test function successfully invoked. Access was granted." is returned in the response.

Debugging

A debug configuration has been added that runs npm start under a debug session. Testing is performed via postman as described above.

cvs-svc-authoriser's People

Contributors

aaron-downing avatar acozianu avatar adpetrescu avatar andrewf-bjss avatar arupdvsa avatar cb-cs avatar daniel-searle avatar dependabot[bot] avatar githanium avatar ian-hodges avatar jonlazarinidd avatar khodderdvsa avatar leifkemp-bjss avatar m-ujaffer avatar martiuk avatar naathanbrown avatar nblore avatar oalexandru avatar paulbenn-bjss avatar sriniarumugam avatar stevenpears-bjss avatar tealorg avatar toketunji avatar tom-bjss avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.