Skip to content

@presencelearning/auth

Angular library wrapping angular-auth-oidc-client with signal-based state, ready-to-use guards, an auth interceptor, and an OAuth callback route.

  • Signal-Based StateAuthService exposes isAuthenticated, currentUser, and accessToken as Angular signals. No subscriptions needed.
  • Single-Call SetupprovideAuth() + withAuthInterceptor() configure everything in app.config.ts
  • Smart Interceptor — Attaches Bearer tokens only to configured secureRoutes. Automatically logs out on 401.
  • Route GuardsauthGuard and createGroupsGuard() protect routes with minimal boilerplate
  • OAuth Callback RoutecreateAuthCallbackRoute() returns a pre-wired Route object
  • Impersonation — RFC 8693 token exchange via createStartImpersonationRoute() and createEndImpersonationRoute(). No consumer wiring required.
  • SSR-Safe StoragelocalStorage / sessionStorage wrappers that fall back gracefully in non-browser environments
  • Token Utilities — Parse, validate, and inspect JWTs without a full OIDC round-trip
Terminal window
npm install @presencelearning/auth
app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideHttpClient } from '@angular/common/http';
import { provideAuth, withAuthInterceptor } from '@presencelearning/auth';
import { routes } from './app.routes';
export const appConfig: ApplicationConfig = {
providers: [
provideRouter(routes),
provideHttpClient(withAuthInterceptor()),
provideAuth({
issuerUrl: environment.auth.issuerUrl,
clientId: environment.auth.clientId,
}),
],
};
app.routes.ts
import { Routes } from '@angular/router';
import { authGuard, createAuthCallbackRoute } from '@presencelearning/auth';
export const routes: Routes = [
createAuthCallbackRoute(),
{
path: 'dashboard',
canActivate: [authGuard],
loadComponent: () => import('./dashboard/dashboard.component'),
},
];
import { Component, inject } from '@angular/core';
import { AuthService } from '@presencelearning/auth';
@Component({
template: `
@if (auth.isAuthenticated()) {
<p>Welcome, {{ auth.currentUser()?.name }}</p>
<button (click)="auth.logout()">Log out</button>
} @else {
<button (click)="auth.login()">Log in</button>
}
`,
})
export class AppComponent {
protected auth = inject(AuthService);
}
  • Angular 18+
  • angular-auth-oidc-client ≥ 18
  • RxJS 7+
  • No session pollingangular-auth-oidc-client handles silent token renewal via refresh tokens
  • No cross-tab sync — Each tab runs its own OIDC check on load

Source: packages/auth