-
Notifications
You must be signed in to change notification settings - Fork 211
Description
I'm submitting a...
- Bug report
- Feature request
- Documentation issue or request
- Question
Current behavior
I have integrated OIDC client from damienbod/angular-auth-oidc-client to support the OpenID Connect Code Flow with PKCE. I need help to define the authentication interface within Ngx-Rocket to work with OIDC library so that it will minimize coding change when upgrading to a new version of ngx-rocket in the future.
Background
I forked the https://github.com/ngx-rocket/starter-kit to https://github.com/workcontrolgit/starter-kit. Then followed the integration instructions from damienbod/angular-auth-oidc-client to add the OIDC client library. At a high level, I made the following code changes
- auth\login.component.* - replaced username/password login with redirect to Identity Provider (ex. IdentityServer4) to support login
- auth\authentication.guard.ts - replaced isauthenticated with OIDC API method
- shell\header\header.component.* - replaced the logout method with OIDC API method
I left the existing auth\authentication.service.* and auth\credentials.service.* in the code base despite they are no longer in use.
Expected behavior
Please consider creating the interface and abstract classes for Authentication and Credentials. The default implementation can be form-based. Additional identity providers can be added and be configurable.
Examples techniques for define interface and abstract classes:
http://dotnetpattern.com/typescript-abstract-class
New set of code to integrate OIDC libary into ngx-rocket
Instead of using the code in ngx-rocket auth\authentication.* and auth\credentials.*, below is a new set of code in auth.service.ts (https://github.com/workcontrolgit/starter-kit/blob/main/src/app/auth/auth.service.ts) referencing the OIDC library
import { Injectable } from '@angular/core';
import { of } from 'rxjs';
import { OidcSecurityService } from 'angular-auth-oidc-client';
@Injectable({ providedIn: 'root' })
export class AuthService {
constructor(private oidcSecurityService: OidcSecurityService) {}
get isLoggedIn() {
return this.oidcSecurityService.isAuthenticated$;
}
get token() {
return this.oidcSecurityService.getToken();
}
get userData() {
return this.oidcSecurityService.userData$;
}
checkAuth() {
return this.oidcSecurityService.checkAuth();
}
doLogin() {
return of(this.oidcSecurityService.authorize());
}
signOut() {
this.oidcSecurityService.logoff();
}
}
Minimal reproduction of the problem with instructions
Environment
Others: