Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authentication #70

Merged
merged 32 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
6e1d756
Install angular oidc client
Jul 21, 2021
c661491
Set oidc config for azure (dyrvold.dev)
Aug 4, 2021
dd17b79
Update eslint schematics
Aug 6, 2021
2f4118e
Introduce login client to Wharf
Aug 6, 2021
0f85fd9
Finish login-modal to login refactor & optimise imports
Aug 9, 2021
55a8400
oidc damien config refinements
Aug 12, 2021
1aee9a4
oidc damien config refinements
Aug 12, 2021
d454f5f
Setup for debug token transmission
Aug 25, 2021
db02d17
Set session storage for cors protection
Sep 3, 2021
cfad70d
Add nullcheck on config from assets
Sep 3, 2021
8d9e8ae
Set one possible interceptor preset for sending IDtokens
Sep 3, 2021
09bcb33
Fine tune more opts oidc
Sep 10, 2021
c7be272
IDtoken to access token transmission switch
Sep 14, 2021
2c16fb1
Add /unauthorized and /forbidden
Sep 15, 2021
4134fe3
Cleanup and assert token push on api request
Sep 15, 2021
e9cd3d4
Set default config azure iver
Oct 28, 2021
32375ff
Add specific allowed origin for bearerTokens
Oct 28, 2021
7b395df
Possible solution to credential/auth/cors issues
Oct 28, 2021
62e4c3c
Temp remove custom header control in interceptor
Oct 28, 2021
9c72173
Cleanup cors debug
Nov 1, 2021
a93e959
Package-lock changes after rebase.
Dec 8, 2021
abcba65
Upgrade angular-oidc-client for rxjs 7 compatability
Dec 8, 2021
ed3bb13
Remove not implemented tooltip
Dec 9, 2021
26f7604
Add commas in listed arrays
Dec 9, 2021
0265d4b
Fix member ordering according to preset rules.
fredx30 Dec 9, 2021
d44b4ec
Remove root compoenent debug info.
fredx30 Dec 9, 2021
9bdcf45
Add changelog
fredx30 Dec 9, 2021
5e787ea
Updated rfc4648 to v1.5.1
applejag Jan 5, 2022
3d9f40f
Load OIDC config from assets/config
fredx30 Jan 17, 2022
c4c574a
Fix OIDC redirection httpparams catch
fredx30 Jan 17, 2022
66b7d05
Crash OIDC lib neatly when running without OIDC config.
fredx30 Jan 17, 2022
5bf060b
Revert "Crash OIDC lib neatly when running without OIDC config."
applejag Feb 15, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ This project tries to follow [SemVer 2.0.0](https://semver.org/).

## v1.6.0 (WIP)

- Adds the ability to login. While logged in this will forward the OIDC
access token to the backend such that a secure user access control is
established. (#70)

- Changed function calls and type names to match the regenerated rest clients
using: (#91)

Expand Down
3 changes: 2 additions & 1 deletion angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "wharf:build"
"browserTarget": "wharf:build",
"proxyConfig": "src/proxy/docker.dev.conf.json"
applejag marked this conversation as resolved.
Show resolved Hide resolved
},
"configurations": {
"production": {
Expand Down
108 changes: 103 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"ng": "ng",
"start": "ng serve",
"start-local": "ng serve --proxy-config src/proxy/local.dev.conf.json",
"build": "ng build",
"build-prod": "node deploy/collect-licenses/collect-licenses.mjs && ng build -c production",
"build-clients": "ng build api-client && ng build import-gitlab-client && ng build import-github-client && ng build import-azuredevops-client",
Expand All @@ -28,10 +29,12 @@
"@angular/platform-browser-dynamic": "^12.1.1",
"@angular/router": "^12.1.1",
"@fortawesome/fontawesome-free": "^5.15.3",
"angular-auth-oidc-client": "^13.1.0",
"ng-event-source": "^1.0.14",
"primeicons": "^4.1.0",
"primeng": "^12.0.0",
"prismjs": "^1.27.0",
"rfc4648": "^1.5.1",
"rxjs": "^7.2.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
Expand All @@ -42,7 +45,7 @@
"@angular-eslint/builder": "12.2.0",
"@angular-eslint/eslint-plugin": "12.2.0",
"@angular-eslint/eslint-plugin-template": "12.2.0",
"@angular-eslint/schematics": "12.2.0",
"@angular-eslint/schematics": "12.3.1",
"@angular-eslint/template-parser": "12.2.0",
"@angular/cli": "^12.1.1",
"@angular/compiler-cli": "^12.1.1",
Expand Down
6 changes: 6 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@ import { ProjectListComponent } from './projects/project-list/project-list.compo
import { ProjectDetailsComponent } from './projects/project-details/project-details.component';
import { BuildDetailsComponent } from './builds/build-details/build-details.component';
import { LicensesComponent } from './licenses/licenses.component';
import { LoginComponent } from './auth/login/login.component';
import { UnauthorizedComponent } from './auth/unauthorized/unauthorized.component';
import { ForbiddenComponent } from './auth/forbidden/forbidden.component';


const routes: Routes = [
{ path: '', component: ProjectListComponent },
{ path: 'project/:projectId', component: ProjectDetailsComponent },
{ path: 'build/:projectId/:buildId', component: BuildDetailsComponent },
{ path: 'third-party-licenses', component: LicensesComponent },
{ path: 'login', component: LoginComponent },
{ path: 'unauthorized', component: UnauthorizedComponent},
{ path: 'forbidden', component: ForbiddenComponent},
applejag marked this conversation as resolved.
Show resolved Hide resolved
];

@NgModule({
Expand Down
18 changes: 16 additions & 2 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
import { Component } from '@angular/core';
import { Component, OnInit } from '@angular/core';
import { OidcSecurityService } from 'angular-auth-oidc-client';

@Component({
selector: 'wh-app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss'],
})
export class AppComponent {
export class AppComponent implements OnInit{
title = 'wharf';

constructor(
private oidcSecurityService: OidcSecurityService,
) {
}

ngOnInit() {
// 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.
this.oidcSecurityService.checkAuth().subscribe(({ isAuthenticated, userData, accessToken, idToken }) => {
console.warn('Authenticated: ', isAuthenticated);
});
}
}
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { SyntaxHighlightService } from './shared/syntax-highlight/syntax-highlig
import { SharedModule } from './shared/pipes/shared.module';
import { NavModule } from './nav/nav.module';
import { LicensesModule } from './licenses/licenses.module';
import { AuthModule } from './auth/auth.module';

@NgModule({
declarations: [
Expand All @@ -34,6 +35,7 @@ import { LicensesModule } from './licenses/licenses.module';
MenuModule,
TooltipModule,
SharedModule,
AuthModule,
],
providers: [
{
Expand Down
29 changes: 29 additions & 0 deletions src/app/auth/auth-config.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { NgModule } from '@angular/core';
import {
AuthModule, OidcSecurityService,
StsConfigHttpLoader,
StsConfigLoader,
} from 'angular-auth-oidc-client';
import { HTTP_INTERCEPTORS } from '@angular/common/http';
import { WharfAuthInterceptor } from './wharf-auth.interceptor';
import { ConfigService } from '../shared/config/config.service';

const authFactory = (configService: ConfigService) => new StsConfigHttpLoader(configService.getOidcConfig$());

@NgModule({
imports: [
AuthModule.forRoot({
loader: {
provide: StsConfigLoader,
useFactory: authFactory,
deps: [ConfigService],
},
}),
],
exports: [AuthModule],
declarations: [],
providers: [
{provide: HTTP_INTERCEPTORS, useClass: WharfAuthInterceptor, multi: true},
],
})
export class AuthConfigModule {}
40 changes: 40 additions & 0 deletions src/app/auth/auth.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule } from '@angular/router';
import { filter } from 'rxjs/operators';
import { DialogModule } from 'primeng/dialog';
import { ButtonModule } from 'primeng/button';
import { EventTypes, OidcSecurityService, PublicEventsService } from 'angular-auth-oidc-client';
import { AuthConfigModule } from './auth-config.module';
import { ForbiddenComponent } from './forbidden/forbidden.component';
import { UnauthorizedComponent } from './unauthorized/unauthorized.component';
import { LoginComponent } from './login/login.component';
import { CardModule } from 'primeng/card';

@NgModule({
declarations: [
ForbiddenComponent,
UnauthorizedComponent,
LoginComponent,
],
imports: [
CommonModule,
AuthConfigModule,
DialogModule,
RouterModule,
ButtonModule,
CardModule,
],
})
export class AuthModule {
constructor(
private readonly eventService: PublicEventsService,
) {
this.eventService
.registerForEvents()
.pipe(filter((notification) => notification.type === EventTypes.ConfigLoaded))
.subscribe((config) => {
console.log('ConfigLoaded', config);
});
}
}
4 changes: 4 additions & 0 deletions src/app/auth/forbidden/forbidden.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<div class="p-d-flex p-ac-center p-ai-center">
<h1>Forbidden</h1>
<p>Code 403</p>
</div>
Empty file.
25 changes: 25 additions & 0 deletions src/app/auth/forbidden/forbidden.component.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { ForbiddenComponent } from './forbidden.component';

describe('ForbiddenComponent', () => {
let component: ForbiddenComponent;
let fixture: ComponentFixture<ForbiddenComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ ForbiddenComponent ],
})
.compileComponents();
});

beforeEach(() => {
fixture = TestBed.createComponent(ForbiddenComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
15 changes: 15 additions & 0 deletions src/app/auth/forbidden/forbidden.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';

@Component({
selector: 'wh-forbidden',
templateUrl: './forbidden.component.html',
styleUrls: ['./forbidden.component.scss'],
})
export class ForbiddenComponent implements OnInit {

constructor() { }

ngOnInit(): void {
}

}
23 changes: 23 additions & 0 deletions src/app/auth/login/login.component.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!-- From https://github.com/damienbod/angular-auth-oidc-client/tree/main/projects/sample-code-flow-refresh-tokens/src/app -->
<div *ngIf="isAuthenticated$|async; else noAuth">
<p-button (click)="logout()">Logout</p-button>
<p-button (click)="logoffAndRevokeTokens()">Logout and revoke tokens</p-button>
<p-button (click)="revokeAccessToken()">Revoke access token</p-button>
<p-button (click)="revokeRefreshToken()">Revoke refresh token</p-button>
<p-button (click)="refreshSession()">Refresh session</p-button>
<hr />
<br />
Is Authenticated: {{ isAuthenticated$|async }}
<br />
userData
<pre>{{ userData$ | async | json }}</pre>
<br />
</div>

<ng-template #noAuth>
<p-button (click)="login()">Login</p-button>
<hr />
</ng-template>

Configuration loaded:
<pre>{{ configuration | json }}</pre>
Empty file.
Loading