npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@glamtime/oauth-oidc-client

v0.0.6

Published

Secure your Angular app using the latest standards for OpenID Connect & OAuth2. Provides support for token refresh, all modern OIDC Identity Providers and more.

Downloads

3

Readme

Angular Lib for OpenID Connect & OAuth2

Secure your Angular app using the latest standards for OpenID Connect & OAuth2. Provides support for token refresh, all modern OIDC Identity Providers and more.

Implemented specs & features

The following client/RP features from OpenID Connect/OAuth2.0 specifications are implemented by openid-client.

Updates to draft specifications (DPoP, JARM, etc) are released as MINOR library versions, if you utilize these specification implementations consider using the tilde ~ operator in your package.json since breaking changes may be introduced as part of these version updates.

Certification


This library has certified that openid-client conforms to the following profiles of the OpenID Connect™ protocol

  • Basic, Implicit, Hybrid, Config, Dynamic, and Form Post RP
  • FAPI 1.0 Advanced RP

Features

Installation

Npm / Yarn

Navigate to the level of your package.json and type

 npm i @glamtime/oauth-oidc-client

or with yarn

 yarn add @glamtime/oauth-oidc-client

Configuration

Import the AuthModule in your module.

import {NgModule} from '@angular/core';
import {OAuthModule} from '@glamtime/oauth-oidc-client';

// ...

@NgModule({
  // ...
  imports: [
    // ...
    OAuthModule.forRoot({
      issuer: '<your authority address here>',
      clientId: '<your clientId>',
      clientSecret: '<your clientSecret>'
    }),
  ],
  // ...
})
export class AppModule {
}

And call the method checkAuth() from your app.component.ts. The method checkAuth() is needed to process the redirect from your Security Token Service and set the correct states. This method must be used to ensure the correct functioning of the library.

import {Component, OnInit} from '@angular/core';
import {OAuthService} from '@glamtime/oauth-oidc-client';

@Component({
  /*...*/
})
export class AppComponent implements OnInit {
  constructor(public authService: OAuthService) {
  }

  ngOnInit() {
    oauthService.checkAuth().subscribe();
  }

  onLogin() {
    this.oauthService.login().subscribe();
  }

  onLogout() {
    this.oauthService.logout().subscribe();
  }
}

Http Interceptor

The HttpClient allows you to implement HTTP interceptors to tap into requests and responses. A common use case would be to intercept any outgoing HTTP request and add an authorization header.

Note: Do not send the access token with requests for which the access token is not intended!

You can configure the resource servers that you want to send a token with in the configuration:

OAuthModule.forRoot({
  config: {
    // ...
    resourceServers: ['https://my-secure-url.com/', 'https://my-second-secure-url.com/'],
  },
}),

The lib provides an own interceptor implementation which you can register like any other HTTP interceptor: and use the interceptor the lib provides you

import {OAuthInterceptor, OAuthModule} from 'angular-auth-oidc-client';

@NgModule({
  // ...
  imports: [
    // ...
    OAuthModule.forRoot(),
    HttpClientModule,
  ],
  providers: [
    {provide: HTTP_INTERCEPTORS, useClass: OAuthInterceptor, multi: true},
    // ...
  ],
})
export class AppModule {
}

If you configured a route to be protected, every child route underneath is protected, too. So if you configure https://example.org/api the token is also added to a request to the route https://example.org/api/users.

In case you are running multiple configurations all the configured routes over all configurations are collected and compared against the currently requested route. If a match is made, the token for the configuration you added the secure route to is being taken and applied in the Authorization header.

Keep in mind that you always can implement your own interceptor as described in the Angular documentation.