MCPcopy Index your code
hub / github.com/damienbod/angular-auth-oidc-client

github.com/damienbod/angular-auth-oidc-client @21.0.2

Chat with this repo
repository ↗ · DeepWiki ↗ · release 21.0.2 ↗ · + Follow
1,088 symbols 3,042 edges 498 files 36 documented · 3%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Angular Lib for OpenID Connect & OAuth2

Build Status npm npm npm code style: prettier Coverage Status

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

Acknowledgements

This library is certified by OpenID Foundation. (RP Implicit and Config RP)

Features

Installation

Ng Add

You can use the schematics and ng add the library.

ng add angular-auth-oidc-client

And answer the questions. A module will be created which encapsulates your configuration.

angular-auth-oidc-client schematics

Npm / Yarn

Navigate to the level of your package.json and type

 npm install angular-auth-oidc-client

or with yarn

 yarn add angular-auth-oidc-client

Documentation

Read the docs here

Samples

Explore the Samples here

Quickstart

For the example of the Code Flow. For further examples please check the Samples Section.

If you have done the installation with the schematics, these modules and files should be available already!

Configuration

Import the AuthModule in your module.

import { NgModule } from '@angular/core';
import { AuthModule, LogLevel } from 'angular-auth-oidc-client';
// ...

@NgModule({
  // ...
  imports: [
    // ...
    AuthModule.forRoot({
      config: {
        authority: '<your authority address here>',
        redirectUrl: window.location.origin,
        postLogoutRedirectUri: window.location.origin,
        clientId: '<your clientId>',
        scope: 'openid profile email offline_access',
        responseType: 'code',
        silentRenew: true,
        useRefreshToken: true,
        logLevel: LogLevel.Debug,
      },
    }),
  ],
  // ...
})
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, inject } from '@angular/core';
import { OidcSecurityService } from 'angular-auth-oidc-client';

@Component({
  /*...*/
})
export class AppComponent implements OnInit {
  private readonly oidcSecurityService = inject(OidcSecurityService);

  ngOnInit() {
    this.oidcSecurityService.checkAuth().subscribe((loginResponse: LoginResponse) => {
      const { isAuthenticated, userData, accessToken, idToken, configId } = loginResponse;

      /*...*/
    });
  }

  login() {
    this.oidcSecurityService.authorize();
  }

  logout() {
    this.oidcSecurityService.logoff().subscribe((result) => console.log(result));
  }
}

Using the access token

You can get the access token by calling the method getAccessToken() on the OidcSecurityService

const token = this.oidcSecurityService.getAccessToken().subscribe(...);

And then you can use it in the HttpHeaders

import { HttpHeaders } from '@angular/common/http';

const token = this.oidcSecurityServices.getAccessToken().subscribe((token) => {
  const httpOptions = {
    headers: new HttpHeaders({
      Authorization: 'Bearer ' + token,
    }),
  };
});

You can use the built in interceptor to add the accesstokens to your request

AuthModule.forRoot({
  config: {
    // ...
    secureRoutes: ['https://my-secure-url.com/', 'https://my-second-secure-url.com/'],
  },
}),
 providers: [
    { provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
  ],

Versions

Current Version is Version 21.x

License

MIT

Authors

Extension points exported contracts — how you extend this code

TestIdpServerOptions (Interface)
(no doc)
projects/integration-tests/test-idp-server/src/TestIdpServer.ts
Schema (Interface)
(no doc)
projects/schematics/src/ng-add/schema.ts
AuthOptions (Interface)
(no doc)
projects/angular-auth-oidc-client/src/lib/auth-options.ts
KeyPair (Interface)
(no doc)
projects/integration-tests/test-idp-server/src/TestIdpServer.ts
ModuleInfo (Interface)
(no doc)
projects/schematics/src/ng-add/models/ng-add-options.ts
LogoutAuthOptions (Interface)
(no doc)
projects/angular-auth-oidc-client/src/lib/auth-options.ts
Session (Interface)
(no doc)
projects/integration-tests/test-idp-server/src/TestIdpServer.ts
StandaloneInfo (Interface)
(no doc)
projects/schematics/src/ng-add/models/ng-add-options.ts

Core symbols most depended-on inside this repo

mockProvider
called by 211
projects/angular-auth-oidc-client/src/test/auto-mock.ts
logDebug
called by 115
projects/angular-auth-oidc-client/src/lib/logging/logger.service.ts
logError
called by 53
projects/angular-auth-oidc-client/src/lib/logging/logger.service.ts
get
called by 51
projects/angular-auth-oidc-client/src/lib/api/data.service.ts
logWarning
called by 48
projects/angular-auth-oidc-client/src/lib/logging/logger.service.ts
read
called by 43
projects/angular-auth-oidc-client/src/lib/storage/browser-storage.service.ts
forRoot
called by 36
projects/angular-auth-oidc-client/src/lib/auth.module.ts
authorize
called by 33
projects/angular-auth-oidc-client/src/lib/oidc.security.service.ts

Shape

Method 535
Class 381
Function 137
Interface 31
Enum 4

Languages

TypeScript100%

Modules by API surface

projects/sample-code-flow-par/node-oidc-provider-docs/lib/helpers/defaults.js52 symbols
projects/angular-auth-oidc-client/src/lib/utils/url/url.service.ts33 symbols
projects/angular-auth-oidc-client/src/lib/oidc.security.service.ts33 symbols
projects/integration-tests/test-idp-server/src/TestIdpServer.ts22 symbols
projects/angular-auth-oidc-client/src/lib/auth-state/auth-state.service.ts20 symbols
projects/angular-auth-oidc-client/src/lib/flows/flows-data.service.ts18 symbols
projects/angular-auth-oidc-client/src/lib/validation/token-validation.service.ts17 symbols
projects/angular-auth-oidc-client/src/lib/config/config.service.ts17 symbols
projects/angular-auth-oidc-client/src/lib/iframe/check-session.service.ts16 symbols
projects/angular-auth-oidc-client/src/lib/user-data/user.service.ts15 symbols
projects/schematics/src/utils/angular-utils.ts13 symbols
projects/angular-auth-oidc-client/src/lib/utils/equality/equality.service.ts13 symbols

For agents

$ claude mcp add angular-auth-oidc-client \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact