GithubHelp home page GithubHelp logo

phi2039 / web-oauth-via-bff Goto Github PK

View Code? Open in Web Editor NEW

This project forked from curityio/spa-using-token-handler

0.0 1.0 0.0 398 KB

SPA Security via a Back End for Front End API

License: Apache License 2.0

Dockerfile 1.79% TypeScript 79.66% Shell 10.25% CSS 0.36% HTML 1.84% JavaScript 6.10%

web-oauth-via-bff's Introduction

Web OAuth via a Back End for Front End API

Quality Availability

A demo SPA secured via a BFF API, following 2021 best practices for browser based apps.

Architecture

We recommend these components, where companies do not need to develop the items colored green:

Components

This provides the following benefits:

  • Standard OpenID Connect security, with only SameSite=strict cookies in the browser
  • Deploy the SPA anywhere
  • Good usability due to the separation of Web and API concerns
  • Only simple code is needed in the SPA, by plugging in Curity components

Prerequisites

Configure Development Domains

Add these entries to your /etc/hosts file:

127.0.0.1 localhost www.example.com api.example.com login.example.com
:1        localhost

Get a License File for the Curity Identity Server

Sign in to the Curity Developer Portal with your Github account.
You can get a Free Community Edition License if you are new to the Curity Identity Server.
Then copy your license.json file into the idsvr folder.

Build the Code

You will need to download and install NodeJS for your operating system. Then run the build script to compile projects and build Docker images.

cd code
./build.sh

Deploy the System

Then run this script to spin up all components in a small Docker Compose network:

cd deployment
./deploy.sh

Use the System

Then browse to http://www.example.com which first presents unauthenticated views:

Unauthenticated Views

Sign in with the following test user name and password:

  • demouser / Password1

Verify that page reloads and multi tab browsing work in a user friendly manner:

Authenticated Views

The example SPA is developed using only simple React code.

View Back End Components

Once the system is deployed you can also browse to these URLs:

View Logs

Use the following type of syntax to find the logs for a particular component:

export BFF_API_CONTAINER_ID=$(docker container ls | grep bff-api | awk '{print $1}')
docker logs -f $BFF_API_CONTAINER_ID
export CURITY_CONTAINER_ID=$(docker container ls | grep curity-idsvr | awk '{print $1}')
docker logs -f $CURITY_CONTAINER_ID
export KONG_CONTAINER_ID=$(docker container ls | grep reverse-proxy | awk '{print $1}')
docker logs -f $KONG_CONTAINER_ID

Run API Tests

If required the messages from the SPA to the BFF API and Business API can be tested via scripts.
These go through an end-to-end HTTP workflow and also verify some error conditions.

cd test
./bff.sh
./api.sh

Run SPA Locally

To run the SPA code locally, omit the web host component from the Docker Compose file.
Then build the SPA in a terminal:

cd code/spa
npm install
npm start

Then build and run the webhost in another terminal:

cd ../webhost
npm install
npm start

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.