Version 2.1 of my OIDC-certified library angular-oauth2-oidc is now available. The library lets you add authentication to Angular applications using external identity providers that speak OAuth 2 or OIDC. Work on this release has kept me busy over the past few weeks.

The following features have been added:

  • A new Config API, while the original one remains supported. It lets you keep the entire configuration in a separate file:
     // auth.config.ts
    
     import { AuthConfig } from 'angular-oauth2-oidc';
    
     export const authConfig: AuthConfig = {
    
       // Url of the Identity Provider
       issuer: 'https://steyer-identity-server.azurewebsites.net/identity',
    
       // URL of the SPA to redirect the user to after login
       redirectUri: window.location.origin + '/index.html',
    
       // The SPA's id. The SPA is registerd with this id at the auth-server
       clientId: 'spa-demo',
    
       // set the scope for the permissions the client should request
       // The first three are defined by OIDC. The 4th is a usecase-specific one
       scope: 'openid profile email voucher',
     }

    Once the configuration object is defined, pass it to the library's configure method:

     import { OAuthService } from 'angular-oauth2-oidc';
     import { JwksValidationHandler } from 'angular-oauth2-oidc';
     import { authConfig } from './auth.config';
     import { Component } from '@angular/core';
    
     @Component({
         selector: 'flight-app',
         templateUrl: './app.component.html'
     })
     export class AppComponent {
    
         constructor(private oauthService: OAuthService) {
           this.configureWithNewConfigApi();
         }
    
         private configureWithNewConfigApi() {
           this.oauthService.configure(authConfig);
           this.oauthService.tokenValidationHandler = new JwksValidationHandler();
           this.oauthService.loadDiscoveryDocumentAndTryLogin();
         }
     }
  • Added convenience methods on OAuthService that simplify common tasks:
    • setupAutomaticSilentRefresh()
    • loadDiscoveryDocumentAndTryLogin()
  • Single Sign out via Session Status Change Notification, as described by the OpenID Connect Session Management specification. In practice, this notifies your application when the user signs out at the login provider:

    Single Sign out via Session Checks

    Your identity provider has to support this feature for it to work, and you must switch it on in the configuration:

     import { AuthConfig } from 'angular-oauth2-oidc';
    
     export const authConfig: AuthConfig = {
       [...]  
       sessionChecksEnabled: true,
       sessionCheckIntervall: 3 * 1000
     }

    The optional sessionCheckIntervall configuration option controls how often the library checks whether the user has signed out at the identity provider. It defaults to 3000 msec.

  • The ValidationHandler, the Config and the OAuthStorage can now be provided through DI:
     [...],
     providers: [
         {provide: AuthConfig, useValue: authConfig },
         { provide: OAuthStorage, useClass: DemoStorage },
         { provide: ValidationHandler, useClass: JwksValidationHandler },
     ],
     [...]
  • Improved structure for the documentation:

    Documentation