Giter Club home page Giter Club logo

oauth.websample2's Introduction

Updated OAuth SPA and API Code Sample

Codacy Badge

Known Vulnerabilities Known Vulnerabilities

Overview

A sample focused on the following OAuth areas for SPAs and APIs:

  • The SPA uses the traditional OpenID connect flow, with session management features
  • The API authorizes access to data using claims from multiple data sources

Views

The SPA is a simple UI with some basic navigation between views, to render fictional resources.
The data is returned from an API that authorizes using claims from multiple sources.

SPA Views

Local Development Quick Start

First ensure that Node.js 20+ is installed, then run the build script:

./build.sh

Custom development domains are used so you must add these entries to your hosts file:

127.0.0.1 localhost web.mycompany.com api.mycompany.com

Next configure Browser SSL Trust for the SSL root certificate:

./api/certs/localhost/mycompany.com.ca.pem

Then run the following script to run the code for both SPA and API:

./run.sh

The browser is invoked and you can sign in with my AWS test credentials:

You can then test all lifecycle operations, including token refresh, multi tab browsing and logout.

Further Information

Red icon 2021 Security Update

  • In 2021 it is instead recommended to keep tokens out of the browser, using a Backend for Frontend
  • See the Final SPA Code Sample for an API driven implementation

Programming Languages

  • Plain TypeScript is used for the SPA, to explain OAuth behaviour in the simplest way
  • Node.js and TypeScript are used to implement the API

Infrastructure

  • Express is used to host both the API and the SPA content
  • AWS Cognito is used as the default Authorization Server
  • The oidc-client-ts library is used by the SPA to implement OpenID Connect
  • The jose library is used by the API to validate JWT access tokens
  • The node-cache library is used to cache extra claims, when access tokens are first received

oauth.websample2's People

Contributors

gary-archer 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.