Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
kcinay055679 committed Aug 29, 2024
1 parent 2437698 commit 45a3d4a
Show file tree
Hide file tree
Showing 11 changed files with 21 additions and 45 deletions.
1 change: 1 addition & 0 deletions docker/local-prod/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ services:
angular:
container_name: angular
image: node:20
user: "${UID:-1000}:${GID:-1000}"
volumes:
- ../../../okr:/opt
- /etc/passwd:/etc/passwd:ro
Expand Down
1 change: 0 additions & 1 deletion frontend/src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ActivatedRouteSnapshot, ResolveFn, RouterModule, Routes } from '@angula
import { OverviewComponent } from './overview/overview.component';
import { EMPTY, of } from 'rxjs';
import { SidepanelComponent } from './shared/custom/sidepanel/sidepanel.component';
import { authGuard } from './shared/guards/auth.guard';
import { AutoLoginPartialRoutesGuard } from 'angular-auth-oidc-client';
import { CallbackComponent } from './callback/callback.component';

Expand Down
6 changes: 2 additions & 4 deletions frontend/src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, Component, OnDestroy, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core';
import { OidcSecurityService } from 'angular-auth-oidc-client';

@Component({
Expand All @@ -10,8 +10,6 @@ import { OidcSecurityService } from 'angular-auth-oidc-client';
export class AppComponent implements OnInit {
constructor(private oidcSecurityService: OidcSecurityService) {}
ngOnInit(): void {
this.oidcSecurityService
.checkAuth()
.subscribe(({ isAuthenticated, userData, accessToken, idToken, configId }) => {});
this.oidcSecurityService.checkAuth().subscribe();
}
}
3 changes: 1 addition & 2 deletions frontend/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,7 @@ export const MY_FORMATS = {
},
{ provide: MAT_DATE_FORMATS, useValue: MY_FORMATS },
{ provide: HTTP_INTERCEPTORS, useClass: OauthInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
// { provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
{
provide: AbstractSecurityStorage,
useClass: DefaultLocalStorageService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,11 @@ export class ApplicationTopBarComponent implements OnInit, OnDestroy {
}

logOut() {
this.oauthService.logoffAndRevokeTokens().subscribe((result) => console.log(result));
this.oauthService.logoff().subscribe();
}

username() {
return this.oauthService.getUserData().pipe(
map((user) => user?.name || 'No username available'),
switchMap((username) => (username ? of(username) : of('no username received'))),
);
return this.oauthService.getUserData().pipe(map((user) => user?.name || ''));
}

openTeamManagement() {
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/app/callback/callback.component.cy.ts

This file was deleted.

2 changes: 1 addition & 1 deletion frontend/src/app/callback/callback.component.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<p>callback works!</p>
<p>You are getting forwarded!</p>
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,12 @@ export class KeyResultFormComponent implements OnInit {
]);

this.users$.subscribe((users) => {
const loggedInUser = this.getUserName();
users.forEach((user) => {
if (user.firstname + ' ' + user.lastname === loggedInUser) {
this.keyResultForm.controls['owner'].setValue(user);
}
this.getUserName().subscribe((userName) => {
users.forEach((user) => {
if (user.firstname + ' ' + user.lastname === userName) {
this.keyResultForm.controls['owner'].setValue(user);
}
});
});
});
}
Expand Down Expand Up @@ -131,7 +132,6 @@ export class KeyResultFormComponent implements OnInit {
updateFormValidity() {}

getUserName() {
// return this.oauthService.getUserData()['name'];
return '';
return this.oauthService.getUserData().pipe(map((user) => user?.name || ''));
}
}
7 changes: 2 additions & 5 deletions frontend/src/app/shared/guards/auth.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,17 @@ import { inject } from '@angular/core';
import { OidcSecurityService } from 'angular-auth-oidc-client';
import { map, take } from 'rxjs';

//Not used, can be deleted
export const authGuard: CanActivateFn = (route, state) => {
const oidcSecurityService = inject(OidcSecurityService);
const router = inject(Router);

return oidcSecurityService.isAuthenticated$.pipe(
take(1),
map(({ isAuthenticated }) => {
// allow navigation if authenticated
if (isAuthenticated) {
return true;
}
return isAuthenticated;

// redirect if not authenticated
return router.parseUrl('/unauthorized');
}),
);
};
10 changes: 3 additions & 7 deletions frontend/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,15 @@ export const environment = {
production: true,
staging: false,
oauth: {
decreaseExpirationBySec: 30,
clearHashAfterLogin: true,
secureRoutes: ['**', 'http://localhost:4200/', 'http://localhost:8080/', 'localhost:8080/'],
authority: 'https://sso.puzzle.ch/auth/realms/pitc',
strictDiscoveryDocumentValidation: false,
customQueryParams: { response_modes_supported: ['query'] },
// redirectUri: 'http://localhost:8080/auth/keycloakopenid/callback',
// redirectUri: `${window.location.protocol}//${window.location.hostname}:${window.location.port}/auth/keycloakopenid/callback${window.location.search}`,
redirectUrl: window.location.origin + '/callback',
postLogoutRedirectUri: window.location.origin,
renewTimeBeforeTokenExpiresInSeconds: 30,
scope: 'profile openid offline_access',
clientId: 'pitc_okr_prod',
responseType: 'code',
showDebugInformation: true,
// showDebugInformation: true,
customParamsRefreshTokenRequest: {
scope: 'openid profile offline_access',
},
Expand Down
8 changes: 2 additions & 6 deletions frontend/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ export const environment = {
production: false,
staging: false,
oauth: {
secureRoutes: ['http://localhost:4200/', 'http://localhost:8080/'],
postLoginRoute: '/dashboard',
// decreaseExpirationBySec: 30,
// clearHashAfterLogin: true,
issuer: 'http://localhost:8095/auth/realms/pitc',
// strictDiscoveryDocumentValidation: false,
redirectUrl: 'http://localhost:4200/callback',
postLogoutRedirectUri: window.location.origin,
postLoginRoute: window.location.origin,
renewTimeBeforeTokenExpiresInSeconds: 30,
scope: 'openid profile offline_access',
clientId: '',
responseType: 'code',
Expand Down

0 comments on commit 45a3d4a

Please sign in to comment.