Skip to content

Commit 584bfc0

Browse files
committed
intgrate libs and security code
keycloak integration
1 parent ffa7aab commit 584bfc0

24 files changed

+700
-140
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ chrome-profiler-events*.json
2323
*.sublime-workspace
2424

2525
# IDE - VSCode
26-
.vscode/*
26+
.vscode/
2727
!.vscode/settings.json
2828
!.vscode/tasks.json
2929
!.vscode/launch.json
3030
!.vscode/extensions.json
31-
.history/*
31+
.history/
3232

3333
# misc
3434
/.sass-cache

docker/env-localhost/env.list

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
# App env vars
2-
API_KEY=ApiKeyDefaultValue
3-
MANAGEMENT_API_URL=http://localhost:19193/management
4-
CATALOG_URL=http://localhost:19193/management
2+
MANAGEMENT_API_URL=http://connector-c1:19193/management
3+
CATALOG_URL=http://connector-c1:19193/management
54
STORAGE_ACCOUNT=company2assets
65
STORAGE_LINK_TEMPLATE=storageexplorer://v=1
76
APP_THEME=theme-2
7+
OAUTH2_ISSUER=http://keycloak:8080/realms/dataspace
8+
OAUTH2_REDIRECT_PATH=/,
9+
OAUTH2_CLIENT_ID=management-client
10+
OAUTH2_SCOPE=openid profile email
11+
OAUTH2_RESPONSE_TYPE=code
12+
OAUTH2_SHOW_DEBUG_INFO=true
13+
OAUTH2_ALLOWED_URLS=http://connector-c1:4200

package-lock.json

Lines changed: 31 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
"@angular/platform-browser": "^17.1.2",
2626
"@angular/platform-browser-dynamic": "^17.1.2",
2727
"@angular/router": "^17.1.2",
28+
"@auth0/angular-jwt": "^5.2.0",
2829
"@think-it-labs/edc-connector-client": "0.3.0",
30+
"angular-oauth2-oidc": "^17.0.2",
2931
"install": "^0.13.0",
3032
"rxjs": "~7.8.1",
3133
"zone.js": "~0.14.2"

src/app/app-config.service.ts

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/app/app-routing.module.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,46 @@
11
import {NgModule} from '@angular/core';
22
import {RouterModule, Routes} from '@angular/router';
3+
import { AuthUserGuard } from "./auth/auth-user.guard";
34

45
export const routes: Routes = [
56
{
67
path: 'catalog',
78
data: {title: 'Catalog Browser', icon: 'sim_card'},
9+
canActivate: [AuthUserGuard],
810
loadChildren: () => import('./pages/catalog/catalog.module').then(m => m.CatalogModule)
911
},
1012
{
1113
path: 'contracts',
1214
data: {title: 'Contracts', icon: 'attachment'},
15+
canActivate: [AuthUserGuard],
1316
loadChildren: () => import('./pages/contracts/contracts.module').then(m => m.ContractsModule)
1417
},
1518
{
1619
path: 'transfer-history',
1720
data: {title: 'Transfer History', icon: 'assignment'},
21+
canActivate: [AuthUserGuard],
1822
loadChildren: () => import('./pages/transfer-history/transfer-history.module').then(m => m.TransferHistoryModule)
1923
},
2024
{
2125
path: 'contract-definitions',
2226
data: {title: 'Contract Definitions', icon: 'rule'},
27+
canActivate: [AuthUserGuard],
2328
loadChildren: () => import('./pages/contract-definitions/contract-definitions.module').then(m => m.ContractDefinitionsModule)
2429
},
2530
{
2631
path: 'policies',
2732
data: {title: 'Policies', icon: 'policy'},
33+
canActivate: [AuthUserGuard],
2834
loadChildren: () => import('./pages/policies/policies.module').then(m => m.PoliciesModule)
2935
},
3036
{
3137
path: 'assets',
3238
data: {title: 'Assets', icon: 'upload'},
39+
canActivate: [AuthUserGuard],
3340
loadChildren: () => import('./pages/assets/assets.module').then(m => m.AssetsModule)
3441
},
3542
{
36-
path: '', redirectTo: 'assets', pathMatch: 'full'
43+
path: '', redirectTo: 'catalog', pathMatch: 'full'
3744
}
3845
];
3946

src/app/app.component.html

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
<app-navigation [class]="themeClass()"></app-navigation>
1+
2+
3+
<app-navigation *ngIf="authService.isAuthenticated()" [class]="themeClass()"></app-navigation>
4+
<h2 *ngIf="!authService.isAuthenticated()" [class]="themeClass()"> NO AUTH! </h2>

src/app/app.component.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,32 @@ import { Component, OnInit } from '@angular/core';
22
import { Title } from '@angular/platform-browser';
33
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
44
import { filter, map } from 'rxjs/operators';
5-
import {AppConfigService} from "./app-config.service";
5+
import { AuthService } from './auth/auth.service';
6+
import { environment } from "../environments/environment";
67

8+
/**
9+
* Main app component
10+
*/
711
@Component({
812
selector: 'app-root',
913
templateUrl: './app.component.html'
1014
})
1115
export class AppComponent implements OnInit {
1216

17+
/**
18+
* Component constructor
19+
*
20+
* @param router Router service
21+
* @param titleService Title service
22+
* @param activatedRoute ActivatedRoute service
23+
* @param authService Auth service
24+
*/
1325
constructor(
1426
private router: Router,
1527
private titleService: Title,
16-
private configService: AppConfigService,
17-
private activatedRoute: ActivatedRoute) {
28+
private activatedRoute: ActivatedRoute,
29+
public authService: AuthService) {
30+
this.authService.runInitialLoginSequence();
1831
}
1932

2033
ngOnInit(): void {
@@ -36,6 +49,6 @@ export class AppComponent implements OnInit {
3649
}
3750

3851
themeClass(): string | undefined {
39-
return this.configService.getConfig()?.theme;
52+
return environment.runtime.theme;
4053
}
4154
}

src/app/app.module.ts

Lines changed: 59 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,43 @@
1-
import {APP_INITIALIZER, NgModule} from '@angular/core';
2-
import {BrowserModule} from '@angular/platform-browser';
1+
import { APP_INITIALIZER, NgModule} from '@angular/core';
2+
import { BrowserModule } from '@angular/platform-browser';
33

4-
import {AppRoutingModule} from './app-routing.module';
5-
import {AppComponent} from './app.component';
6-
import {BrowserAnimationsModule} from '@angular/platform-browser/animations';
4+
import { AppRoutingModule } from './app-routing.module';
5+
import { AppComponent } from './app.component';
6+
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
77

8-
import {LayoutModule} from '@angular/cdk/layout';
9-
import {MatToolbarModule} from '@angular/material/toolbar';
10-
import {MatButtonModule} from '@angular/material/button';
11-
import {MatSidenavModule} from '@angular/material/sidenav';
12-
import {MatIconModule} from '@angular/material/icon';
13-
import {MatListModule} from '@angular/material/list';
14-
import {MAT_FORM_FIELD_DEFAULT_OPTIONS} from '@angular/material/form-field';
15-
import {AppConfigService} from "./app-config.service";
16-
import {MatSnackBarModule} from "@angular/material/snack-bar";
17-
import {CONNECTOR_CATALOG_API, CONNECTOR_MANAGEMENT_API, DATA_ADDRESS_TYPES} from "./shared/utils/app.constants";
18-
import {HTTP_INTERCEPTORS, HttpClientModule} from "@angular/common/http";
19-
import {EdcApiKeyInterceptor} from "./shared/interceptors/apikey.interceptor";
20-
import {environment} from "../environments/environment";
8+
import { LayoutModule } from '@angular/cdk/layout';
9+
import { MatToolbarModule } from '@angular/material/toolbar';
10+
import { MatButtonModule } from '@angular/material/button';
11+
import { MatSidenavModule } from '@angular/material/sidenav';
12+
import { MatIconModule } from '@angular/material/icon';
13+
import { MatListModule } from '@angular/material/list';
14+
import { MAT_FORM_FIELD_DEFAULT_OPTIONS } from '@angular/material/form-field';
15+
import { MatSnackBarModule } from "@angular/material/snack-bar";
16+
import { CONNECTOR_CATALOG_API, CONNECTOR_MANAGEMENT_API, DATA_ADDRESS_TYPES } from "./shared/utils/app.constants";
17+
import { HTTP_INTERCEPTORS, HttpClientModule } from "@angular/common/http";
18+
import { Oauth2Interceptor } from "./shared/interceptors/aouth2.interceptor";
19+
import { environment } from "../environments/environment";
2120
import { EdcConnectorClient } from "@think-it-labs/edc-connector-client";
22-
import {MatCardModule} from '@angular/material/card';
23-
import {SharedModule} from './shared/shared.module';
21+
import { MatCardModule } from '@angular/material/card';
22+
import { SharedModule } from './shared/shared.module';
23+
24+
import { AuthService } from './auth/auth.service';
25+
import { JwtModule, JWT_OPTIONS } from '@auth0/angular-jwt';
26+
import { OAuthModule, OAuthModuleConfig } from 'angular-oauth2-oidc';
27+
28+
/**
29+
* Declare the JWT Module configuration. It will be used to work with tokens, like decode the access token
30+
*
31+
* @returns JWT Module config
32+
*/
33+
export function jwtOptionsFactory() {
34+
return {
35+
tokenGetter: () => {
36+
return sessionStorage.getItem(environment.jwt.storageKey);
37+
},
38+
allowedDomains: environment.runtime.oauth2.allowedUrls.split(',')
39+
}
40+
}
2441

2542
@NgModule({
2643
imports: [
@@ -36,54 +53,51 @@ import {SharedModule} from './shared/shared.module';
3653
MatSnackBarModule,
3754
MatCardModule,
3855
SharedModule,
39-
HttpClientModule
56+
HttpClientModule,
57+
JwtModule.forRoot({
58+
jwtOptionsProvider: {
59+
provide: JWT_OPTIONS,
60+
useFactory: jwtOptionsFactory
61+
}
62+
}),
63+
OAuthModule.forRoot({
64+
resourceServer: {
65+
allowedUrls: environment.runtime.oauth2.allowedUrls.split(','),
66+
// Add Auth header with Bearer token to all requests
67+
sendAccessToken: true
68+
}
69+
})
4070
],
4171
declarations: [
4272
AppComponent
4373
],
4474
providers: [
45-
{
46-
provide: APP_INITIALIZER,
47-
useFactory: (configService: AppConfigService) => () => configService.loadConfig(),
48-
deps: [AppConfigService],
49-
multi: true
50-
},
75+
AuthService,
5176
{provide: MAT_FORM_FIELD_DEFAULT_OPTIONS, useValue: {appearance: 'outline'}},
5277
{
5378
provide: CONNECTOR_MANAGEMENT_API,
54-
useFactory: (s: AppConfigService) => s.getConfig()?.managementApiUrl,
55-
deps: [AppConfigService]
79+
useFactory: () => environment.runtime.managementApiUrl
5680
},
5781
{
5882
provide: CONNECTOR_CATALOG_API,
59-
useFactory: (s: AppConfigService) => s.getConfig()?.catalogUrl,
60-
deps: [AppConfigService]
83+
useFactory: () => environment.runtime.catalogUrl
6184
},
6285
{
6386
provide: 'HOME_CONNECTOR_STORAGE_ACCOUNT',
64-
useFactory: (s: AppConfigService) => s.getConfig()?.storageAccount,
65-
deps: [AppConfigService]
87+
useFactory: () => environment.runtime.storageAccount
6688
},
6789
{
6890
provide: 'STORAGE_TYPES',
6991
useFactory: () => [{id: DATA_ADDRESS_TYPES.httpData, name: DATA_ADDRESS_TYPES.httpData}, {id: DATA_ADDRESS_TYPES.amazonS3, name: DATA_ADDRESS_TYPES.amazonS3}],
7092
},
71-
{
72-
provide: HTTP_INTERCEPTORS, multi: true, useFactory: () => {
73-
let i = new EdcApiKeyInterceptor();
74-
i.apiKey = environment.apiKey
75-
return i;
76-
}, deps: [AppConfigService]
77-
},
93+
{ provide: HTTP_INTERCEPTORS, useClass: Oauth2Interceptor, multi: true },
7894
{
7995
provide: EdcConnectorClient,
80-
useFactory: (s: AppConfigService) => {
96+
useFactory: () => {
8197
return new EdcConnectorClient.Builder()
82-
.apiToken(environment.apiKey)
83-
.managementUrl(s.getConfig()?.managementApiUrl as string)
98+
.managementUrl(environment.runtime.managementApiUrl)
8499
.build();
85-
},
86-
deps: [AppConfigService]
100+
}
87101
}
88102
],
89103
bootstrap: [AppComponent]

0 commit comments

Comments
 (0)