
Security News
Axios Supply Chain Attack Reaches OpenAI macOS Signing Pipeline, Forces Certificate Rotation
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.
@ppwcode/ng-oauth
Advanced tools
This module is the ppwcode-way of dealing with OAuth in an Angular application.
This module is the ppwcode-way of dealing with OAuth in an Angular application.
The module ships with a token interceptor, a guard and a service managing the authentication process and using the token.
Run the following command to install the package using NPM:
npm install @ppwcode/ng-oauth
In case you're using Yarn:
yarn add @ppwcode/ng-oauth
Convert your application to run over https in development by changing the configuration of the angular.json file:
{
"projects": {
"my-project": {
"architect": {
"serve": {
"configurations": {
"development": {
"port": 443,
"ssl": true
}
}
}
}
}
}
}
To add the module to your application, call the .forRoot method when importing in your root application module. By
adding the PpwcodeOAuthModule to your application module, this will automatically add the TokenInterceptor.
import { PpwcodeOAuthModule } from '@ppwcode/ng-oauth';
@NgModule({
imports: [
PpwcodeOAuthModule.forRoot([/** prefixes of urls to send token to */])
]
})
In the .forRoot call, specify an array of prefixes for urls to send the token to.
The OAuth services used internally require some configuration parameters to be able to run the OAuth flow. Pass the
configuration in your main AppComponent:
import { OAuthService } from '@ppwcode/ng-oauth';
export class AppComponent {
constructor(private readonly oAuthService: OAuthService) {
this.configureOAuth();
}
private configureOAuth(): void {
this.oAuthService.configureOAuth({
issuer: '',
redirectUri: '',
clientId: '',
resource: '',
responseType: '',
scope: ''
});
}
}
Add the OAuthAuthenticatedGuard to the routes that you want to be accessible by users that are authenticated:
import { Routes } from '@angular/router';
const routes: Routes = [
{
path: 'awesome',
component: MyAwesomeComponent,
canActivate: [OAuthAuthenticatedGuard]
}
];
This can even be applied on lazy loaded modules:
import { OAuthAuthenticatedGuard } from '@ppwcode/ng-oauth';
const routes: Routes = [
{
path: 'children',
loadChildren: () => import('./children/children.module').then((m) => m.ChildrenModule),
canActivate: [OAuthAuthenticatedGuard]
}
];
The OAuthService.getIdentityClaims function will give you the user claims or null if the user is not authenticated.
Because the claims can have any structure, you have to provide type safety yourself by leveraging the generic of the
function and make the interface extend Record<string, unknown>.
import { OAuthService } from '@ppwcode/ng-oauth';
export interface UserClaims extends Record<string, unknown> {
unique_name: string;
upn: string;
}
export class MyComponent {
userClaims!: UserClaims | null;
constructor(private readonly oAuthService: OAuthService) {}
ngOnInit() {
this.userClaims = this.oAuthService.getIdentityClaims<UserClaims>();
}
}
This will not limit the claims that are returned. Claims that have not been defined in the type are also returned.
FAQs
This module is the ppwcode-way of dealing with OAuth in an Angular application.
The npm package @ppwcode/ng-oauth receives a total of 1 weekly downloads. As such, @ppwcode/ng-oauth popularity was classified as not popular.
We found that @ppwcode/ng-oauth demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
OpenAI rotated macOS signing certificates after a malicious Axios package reached its CI pipeline in a broader software supply chain attack.

Security News
Open source is under attack because of how much value it creates. It has been the foundation of every major software innovation for the last three decades. This is not the time to walk away from it.

Security News
Socket CEO Feross Aboukhadijeh breaks down how North Korea hijacked Axios and what it means for the future of software supply chain security.