• Stars
    star
    258
  • Rank 158,189 (Top 4 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created over 6 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Basic example of how to integrate the angular-oauth2-oidc library in an Angular SPA utilizing AuthGuards.

Example angular-oauth2-oidc with AuthGuard

This repository shows a basic Angular CLI application with the angular-oauth2-oidc library and Angular AuthGuards.

Lint-Build-Test GitHub Actions Status

âš  Third-party Cookies

TLDR 👉 See my "SPA Necromancy" blogpost for all options and workarounds known to me.

Browser vendors are implementing increasingly strict rules around cookies. This is increasingly problematic for SPA's with their Identity Server on a third-party domain. Most notably problems occur if the "silent refresh via an iframe" technique is used.

This repository uses that technique currently, starting with a silentRefresh(). This will fire up an iframe to load an IDS page with noprompt, hoping cookies get sent along to so the IDS can see if a user is logged in.

Safari will block cookies from being sent, prompting a leading OAuth/OpenID community member to write "SPAs are dead!?". In fact, if you fire up this sample repository on localhost, which talks to demo.duendesoftware.com (another domain!), and use it in Safari: you will notice that the silent refresh technique already fails!

For reference, see issue #40, or my blogpost that explains workarounds and solutions.

Features

âš  To see the Implicit Flow refer to the implicit-flow branch (which might be getting outdated, since Code Flow is now the recommended flow).

This demonstrates:

  • Use of the Code+PKCE Flow (so no JWKS validation)
  • Async but mandatory bootstrapping (via an APP_INITIALIZER) before the rest of the app can run
  • Modules (core, shared, and two feature modules)
  • An auth guard that forces you to login when navigating to protected routes
  • An auth guard that just prevents you from navigating to protected routes
  • Asynchronous loading of login information (and thus async auth guards)
  • Using localStorage for storing tokens (use at your own risk!)
  • Loading IDS details from its discovery document
  • Trying refresh on app startup before potientially starting a login flow
  • OpenID's external logout features

Most interesting features can be found in the core module.

Implicit Flow

If you need an example of the Implicit Flow check out the last commit with that flow or even earlier versions. For new applications Code+PKCE flow is recommended for JavaScript clients, and this example repository now demonstrates this as the main use case.

Usage

This repository has been scaffolded with the Angular 5 CLI, then later upgraded to newer versions of the Angular CLI. To use the repository:

  1. Clone this repository
  2. Run npm install to get the dependencies
  3. Run npm run start (or start-with-ssl) to get it running on http://localhost:4200 (or https://localhost:4200)

This connects to the demo Duende IdentityServer instance also used in the library's examples. The credentials and ways of logging in are disclosed on the login page itself (as it's only a demo server).

You could also connect to your own IdentityServer by changing auth-config.ts. Note that your server must whitelist both http://localhost:4200/index.html and http://localhost:4200/silent-refresh.html for this to work.

Differences between Identity Server options

This repository demonstrates features using https://demo.duendesoftware.com (Duende IdentityServer). There are various other server side solutions available, each with their own intricacies. This codebase does not keep track itself of the specifics for each other server side solution. Instead, we recommend you look for specific guidance for other solutions elsewhere. Here are some potential starting points you could consider:

Feel free to open an issue and PR if you want to add additional pieces of guidance to this section.

Example

The application is supposed to look somewhat like this:

Application Screenshot

More Repositories

1

advent-of-code-charts

Inject charts in your private leaderboard page for Advent of Code
JavaScript
120
star
2

advent-of-code-surveys

Advent of Code (unofficial) Surveys
JavaScript
41
star
3

sample-auth0-angular-oauth2-oidc

Sample for connecting your Angular 6+ app to Auth0 with implicit flow
TypeScript
22
star
4

advent-of-code-2018

Solutions to the Advent of Code 2018 edition by Jeroen Heijmans.
C#
6
star
5

advent-of-code-2017

Solutions to the Advent of Code 2017 edition by Jeroen Heijmans.
JavaScript
5
star
6

sample-godot-drag-drop-from-control-to-node2d

Shows how Godot Drag & Drop can work between Control and Node2D nodes.
GDScript
4
star
7

advent-of-code-2020

Solutions for Advent of Code 2020 (in TypeScript)
TypeScript
4
star
8

advent-of-code-2021

Solutions for Advent of Code 2020 (in php)
PHP
4
star
9

sample-xunit-unreliable-fact

Example of an UnreliableFact xUnit attribute implementation
C#
3
star
10

sample-sendgrid-mailkit-app

Showcase how SendGrid and MailKit work together
C#
3
star
11

sample-nextjs-with-azure-b2c

Showcase NextJS working with Azure B2C using the MSAL library for OAuth2/OpenID
TypeScript
3
star
12

tierdom

Tiered list of.... anything!
TypeScript
3
star
13

sample-azure-search-integration-tests

Shows how to set up integration tests for Azure Search using xUnit and .NET Core.
C#
3
star
14

advent-of-code-2023

Solutions for Advent of Code 2023
TypeScript
3
star
15

dotagrid

Simple little app to create hero layouts for the game Dota 2. Choose from a few basic templates, or create your own custom grid, and then load it up in Dota.
JavaScript
3
star
16

sample-godot-sub-viewport-and-input-events

Shows Godot 4 having Pickable bodies inside a SubViewport, with InputEvents.
GDScript
3
star
17

sample-ef-core-in-asp-net-core

Sample repository with EF Core in an ASP.NET Core API application
C#
3
star
18

presentation-learning-at-lightning-speed

Presentation titled "Learning at Lightning Speed"
JavaScript
2
star
19

sample-angular-nested-forms

Angular sample showing nested reactive forms
TypeScript
2
star
20

advent-of-code-2019

Solutions for the 2019 edition of Advent of Code
Python
2
star
21

coding-dojo-implicit-flow

Learn how OAuth2 Implicit Flow works (with help of .NET Core IdentityServer4 and Angular-OAuth2-OIDC).
2
star
22

advent-of-code-2022

Solutions for Advent of Code 2022 (in Kotlin and/or JavaScript)
JavaScript
2
star
23

sample-asp-net-core-auth-policies

Sample application to use Authorization Policies
C#
2
star
24

sample-angular-azure-devops

Showcase Azure Devops pipelines for an Angular application
TypeScript
2
star
25

presentation-getting-your-first-100-github-stars

Presentation "Getting Your First 100 GitHub Stars" (Reveal.js-based)
HTML
2
star
26

sample-angular-service-testing

Examples of how one could test Angular services
TypeScript
2
star
27

sample-tailwind-background-stacking

Showcase how you can stack multiple different kinds of backgrounds
HTML
2
star
28

repro-godot-bounce-bug

Repository to reproduce an issue with Godot 4 around bouncing of bodies
2
star
29

sample-asp-net-core-integration-tests-for-duo-apis

Integration tests for two APIs calling eachother
C#
2
star
30

sample-godot-node2d-input-handling

Example for Godot 4 input handling when Node2D nodes are involved
GDScript
2
star
31

sample-angular-ngrx-with-feature-modules

This application is meant as a sample and playground for Angular 8+ with feature modules, combined with NgRx.
TypeScript
2
star
32

sample-asp-net-core-integration-tests-di

Demonstrate how to use DI and ConfigureTestServices in xUnit based ASP.NET Core 2.2 integration tests
C#
2
star
33

infinibattle-2023-excel-bot

Bot for the 2023 edition of Infinibattle
C#
2
star
34

sample-identityserver4-with-appinsights

Sample repository with ASP.NET Core, IdentityServer4, and AppInsights
C#
2
star
35

battle-top

Responsive single-page web application to assist in bookkeeping things like Characters, Initiative, Hit Points, Conditions, et cetera, during D20-based table top RPG sessions.
JavaScript
2
star
36

sample-angular-fixate-unit-test-random-seed

Sample of how randomization works in Angular/Jasmine/Karma unit tests
HTML
2
star
37

connect-four

Small web application where two players can play a simple version of the classic Connect-Four board game in a browser, serving as a "Hello World on Steroids" for experimenting with open source libraries.
JavaScript
2
star
38

sample-angular-oauth2-oidc-basic

Basic bare bones example of how the angular-oauth2-oidc library works
1
star
39

empgrid

Grid of online presences of a group of people
C#
1
star
40

onitama-bot-angsthaas

Fearful little bot for Infi's Onitama bot challenge.
C#
1
star
41

benchmark-ef-core

Benchmarking some EF Core features
C#
1
star
42

infinibattle-2022-kapitein-hoek

Bot for the 2022 edition of Infinibattle
C#
1
star
43

sample-react-native-decorated-redux-persist-storage

Sample ReactNative App with Decorated Storage for Redux-Persist
Java
1
star
44

sample-nextjs-with-typeform

Sample NextJS application which includes Typeform integration
TypeScript
1
star
45

sample-asp-net-core-authorization-handlers

Sample for combining Authorization Policies in ASP.NET Core
C#
1
star
46

study-notes-msft-az-305

Notes taken while studying for AZ-305 (2024-Q1)
HTML
1
star
47

sample-nextjs-with-jotform

Sample NextJS application which includes Jotform integration
TypeScript
1
star
48

sample-asp-net-core-auth-issuer

Sandbox for testing with Issuer and Authority in IDS4
HTML
1
star
49

is-het-bbq-weer-vandaag

HTML
1
star
50

sample-css-gradients-basics

Showcasing some of the basics of CSS gradients.
HTML
1
star
51

repro-vite-build-log-warnings-for-external-assets

To reproduce https://github.com/vitejs/vite/issues/10766
CSS
1
star
52

sample-nextjs-middleware-with-cached-redirects

Sample NextJS App with Cached Dynamic Redirects
TypeScript
1
star
53

sample-vitest-for-mantine-datatable

Sample repository showing how to write Vitest unit and snapshot tests for Mantine-DataTable
TypeScript
1
star