damienbod/angular-auth-oidc-client
소개
OpenID Connect, PKCE를 사용하는 OAuth 코드 플로, 리프레시 토큰, 암시적 플로를 위한 npm 패키지
보안 및 개인정보 보호What you can do
- Code samples for most of the common use cases
- Supports schematics via ng add support
- Supports all modern OIDC identity providers
- Supports OpenID Connect Code Flow with PKCE
측정된 스타 증가
- in 24h
- 0
- in 7 days
- +2
- in 15 days
- +2
- in 1 month
- 0
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalAngular 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.
Acknowledgements
This library is certified by OpenID Foundation. (RP Implicit and Config RP)
Features
- Code samples for most of the common use cases
- Supports schematics via
ng addsupport - Supports all modern OIDC identity providers
- Supports OpenID Connect Code Flow with PKCE
- Supports Code Flow PKCE with Refresh tokens
- Supports OpenID Connect Implicit Flow
- Supports OpenID Connect Session Management 1.0
- Supports RFC7009 - OAuth 2.0 Token Revocation
- Supports RFC7636 - Proof Key for Code Exchange (PKCE)
- Supports RFC9126 - OAuth 2.0 Pushed Authorization Requests (PAR)
- Semantic releases
- Github actions
- Modern coding guidelines with prettier, husky
- Up to date documentation
- Implements OIDC validation as specified, complete client side validation for REQUIRED features
- Validates id_token signatures using WebCrypto with RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384 and EdDSA / Ed25519 (RFC 9864)
- Supports authentication using redirect or popup
Installation
Ng Add
You can use the schematics and ng add the library.
ng add angular-auth-oidc-client
And answer the questions. The schematic detects how your application is bootstrapped and configures the library accordingly:
- Standalone applications (
bootstrapApplication): anauth.config.tsis created andprovideAuth(authConfig)is added to the providers of your application config. - NgModule applications: an
AuthConfigModuleis created and imported in yourAppModule.
You can choose the setup explicitly with --standalone or --legacy-modules:
ng add angular-auth-oidc-client --standalone
ng add angular-auth-oidc-client --legacy-modules
--standalone also works in NgModule applications, provideAuth(authConfig) is then added to the providers of the AppModule. --legacy-modules requires an AppModule. The two options cannot be combined.

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
Samples
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 { LoginResponse, 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
this.oidcSecurityService.getAccessToken().subscribe((token) => {
/* ... */
});
And then you can use it in the HttpHeaders
import { HttpHeaders } from '@angular/common/http';
this.oidcSecurityService.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 22.x
- Info about Version 21
- Info about Version 20
- Info about Version 19
- Info about Version 18
- Info about Version 17
- Info about Version 16
- Info about Version 15
- Info about Version 14
- Info about Version 13
- Info about Version 12
- Info about Version 11
- Info about Version 10
License
Authors
Maintained by
Maintained by offering.solutions.
관련 프로젝트 살펴보기
불러오는 중…

