返回排行榜

damienbod/angular-auth-oidc-client

TypeScriptnpmjs.com/package/angular-auth-oidc-client

npm package for OpenID Connect, OAuth Code Flow with PKCE, Refresh tokens, Implicit Flow

openidangularimplicit-flownpmsecurityoauth2oidcauthnauthidentityopenidconnectauthentication
Star 增长趋势
Star
1.2k
Forks
450
周增长
Issues
254
5001k
2017年6月2020年6月2023年7月2026年7月
制品库npmnpm install angular-auth-oidc-client
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 {}

When using silentRenew together with useRefreshToken, requesting the offline_access scope is common and remains the default recommendation. Some providers support refresh token renewal in the browser without offline_access. In those cases, you can suppress the configuration warning with disableRefreshTokenOfflineAccessScopeWarning: true.

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

相关仓库
jaredhanson/passport

Simple, unobtrusive authentication for Node.js.

JavaScriptnpmMIT Licensenodejsexpress
passportjs.org
23.5k1.3k
ory/hydra

Internet-scale OpenID Certified™ OpenID Connect and OAuth2.1 provider that integrates with your user management through headless APIs. Solve OIDC/OAuth2 user cases over night. Consume as a service on Ory Network or self-host. Trusted by OpenAI and many others for scale and security. Written in Go.

GoGo ModulesApache License 2.0hydraoauth2
ory.com
17.4k1.6k
panva/node-oidc-provider

OpenID Certified™ OAuth 2.0 Authorization Server implementation for Node.js

JavaScriptnpmMIT Licenseopenidoidc
3.8k790
DefGuard/defguard

Zero-Trust access management with true WireGuard® 2FA/MFA

Rustcrates.ioOthermultifactor-authenticationopenid
defguard.net
2.8k107
panva/openid-client

OAuth 2 / OpenID Connect Client API for JavaScript Runtimes

TypeScriptnpmMIT Licenseoidcopenid
2.4k409
ory/polis

Streamline your web application's authentication with Polis, an SSO service supporting SAML and OpenID Connect protocols. Beyond enterprise-grade Single Sign-On, it also supports Directory Sync via the SCIM 2.0 protocol for automatic user and group provisioning/de-provisioning.

TypeScriptnpmApache License 2.0enterprise-softwaresaml
ory.com
2.3k224
kdeldycke/awesome-iam

👤 Identity and Access Management knowledge for cloud platforms

Creative Commons Zero v1.0 Universaliamsecret-management
2.2k185
greenpau/caddy-security

🔐 Authentication, Authorization, and Accounting (AAA) App and Plugin for Caddy v2. 💎 Implements Form-Based, Basic, Local, LDAP, OpenID Connect, OAuth 2.0 (Github, Google, Facebook, Okta, etc.), SAML Authentication. MFA/2FA with App Authenticators and Yubico. 💎 Authorization with JWT/PASETO tokens. 🔐

GoGo ModulesApache License 2.0caddy-plugincaddy2
authcrunch.com
2.2k102
boxyhq/jackson

🔥 Streamline your web application's authentication with Jackson, an SSO service supporting SAML and OpenID Connect protocols. Beyond enterprise-grade Single Sign-On, it also supports Directory Sync via the SCIM 2.0 protocol for automatic user and group provisioning/de-provisioning. 🤩

TypeScriptnpmApache License 2.0enterprise-softwaresaml
boxyhq.com/docs/jackson/overview
2k169
longguikeji/arkid

一账通是一款开源的统一身份认证授权管理解决方案,支持多种标准协议(LDAP, OAuth2, SAML, OpenID),细粒度权限控制,完整的WEB管理功能,钉钉、企业微信集成等,QQ group: 167885406

PythonPyPIGNU Affero General Public License v3.0openidsaml
longguikeji.github.io/arkid/
1.3k251
dvsekhvalnov/jose-jwt

Ultimate Javascript Object Signing and Encryption (JOSE), JSON Web Token (JWT) and Json Web Keys (JWK) Implementation for .NET and .NET Core

C#MIT Licensejosejwt
1k192
TerribleDev/OwinOAuthProviders

OAuth providers for Owin

C#oauth-providerc-sharp
504235