diff --git a/package-lock.json b/package-lock.json index 812ef8b..9756ec9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3798,14 +3798,6 @@ "integrity": "sha1-l6ERlkmyEa0zaR2fn0hqjsn74KM=", "dev": true }, - "angular-oauth2-oidc": { - "version": "9.2.2", - "resolved": "https://registry.npmjs.org/angular-oauth2-oidc/-/angular-oauth2-oidc-9.2.2.tgz", - "integrity": "sha512-aMQXeujzhubvxGw3ujw9FGwTC+L8m7CXnzVntpNJRkJsgMiuZFrXzgeiG87tvAE61J+PlOVIb/UkJjYDgDVU6Q==", - "requires": { - "js-sha256": "^0.9.0" - } - }, "ansi-colors": { "version": "3.2.4", "resolved": "https://registry.npmjs.org/ansi-colors/-/ansi-colors-3.2.4.tgz", @@ -8483,11 +8475,6 @@ } } }, - "js-sha256": { - "version": "0.9.0", - "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", - "integrity": "sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==" - }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", diff --git a/package.json b/package.json index 7fb0673..284bc6d 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,6 @@ "@angular/platform-browser": "~11.1.1", "@angular/platform-browser-dynamic": "~11.1.1", "@angular/router": "~11.1.1", - "angular-oauth2-oidc": "^9.2.2", "moment": "^2.29.1", "rxjs": "~6.6.0", "tslib": "^1.14.1", diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 02e222f..a5144ff 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,15 +1,11 @@ import { NgModule } from '@angular/core'; import { FormsModule, ReactiveFormsModule } from '@angular/forms'; import { BrowserModule } from '@angular/platform-browser'; -import { OAuthModule, OAuthStorage } from 'angular-oauth2-oidc'; import { HttpClientModule } from '@angular/common/http'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; -import { NgxMatDatetimePickerModule, NgxMatTimepickerModule } from '@angular-material-components/datetime-picker'; +import { NgxMatDatetimePickerModule } from '@angular-material-components/datetime-picker'; import { AppComponent } from './app.component'; -import { USER_API_URL, TRAVEL_API_URL } from './app.config'; -import { SharedModule } from './shared/shared.module'; -// import { useHash } from '../flags'; import { MaterialModule } from './material/material.module'; import { HomeComponent } from './pages/home/home.component'; @@ -25,24 +21,12 @@ import { NgxMatMomentModule } from '@angular-material-components/moment-adapter' import { AppRouterModule } from './router.module'; import { AvailablePlacesPipe } from './pipes/available-places.pipe'; -// We need a factory, since localStorage is not available during AOT build time. -export function storageFactory(): OAuthStorage { - return localStorage; -} - @NgModule({ imports: [ BrowserModule, FormsModule, ReactiveFormsModule, HttpClientModule, - SharedModule.forRoot(), - OAuthModule.forRoot({ - resourceServer: { - allowedUrls: [USER_API_URL, TRAVEL_API_URL], - sendAccessToken: true, - }, - }), BrowserAnimationsModule, AppRouterModule, MaterialModule, @@ -62,7 +46,6 @@ export function storageFactory(): OAuthStorage { AvailablePlacesPipe ], providers: [ - { provide: OAuthStorage, useFactory: storageFactory } // (useHash) ? { provide: LocationStrategy, useClass: HashLocationStrategy } : [], // {provide: AuthConfig, useValue: authConfig }, // { provide: OAuthStorage, useValue: localStorage }, diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index bb1f725..2ae43ed 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -1,8 +1,5 @@ import { Injectable } from '@angular/core'; -import { OAuthService } from 'angular-oauth2-oidc'; import { BehaviorSubject } from 'rxjs'; -import { filter } from 'rxjs/operators'; -import { authConfig } from '../auth.config'; import { User } from '../entities/user'; import { ChatService } from './chat.service'; @@ -20,23 +17,25 @@ export class AuthService { public logged$ = this.loggedSubject.asObservable(); constructor( - private oauthService: OAuthService, private chatService: ChatService ) { } login(): void { - this.oauthService.initLoginFlow(); } logout(): void { - this.oauthService.revokeTokenAndLogout(); } currentUser(): User { - const claims = this.oauthService.getIdentityClaims(); + // const claims = this.oauthService.getIdentityClaims(); + const claims = null; return User.fromClaims(claims); } + stopAutomaticRefresh(): void { + // this.oauthService.stopAutomaticRefresh(); + } + async configureAndTryLogin(chatLoginToken: string): Promise { this.configureOauth(); @@ -67,43 +66,11 @@ export class AuthService { return AuthState.NotLogged; } - stopAutomaticRefresh(): void { - this.oauthService.stopAutomaticRefresh(); - } - private configureOauth(): void { - this.oauthService.configure(authConfig); - this.oauthService.setupAutomaticSilentRefresh(); - - this.oauthService.events - .pipe(filter((e) => e.type === 'token_received')) - .subscribe((_) => { - console.log('auth.service token_received state=', this.oauthService.state); - }); + } private async tryOauthLogin(): Promise { - await this.oauthService.loadDiscoveryDocumentAndTryLogin(); - if (this.oauthService.getIdentityClaims() != null) { - console.log('IDENTITY CLAIMS'); - console.log(this.oauthService.getIdentityClaims()); - if (this.oauthService.hasValidIdToken() && this.oauthService.hasValidAccessToken()) { - console.log('NO NEED FOR TOKEN REFRESH'); - return true; - } - else { - try { - await this.oauthService.refreshToken(); - console.log('TOKEN REFRESHED'); - return true; - } - catch (e) { - console.log('ERROR REFRESHING TOKEN: ' + e); - return false; - } - } - } - console.log('NOT LOGGED!'); return false; } } diff --git a/src/app/services/chat.service.ts b/src/app/services/chat.service.ts index 9e6ad08..1807765 100644 --- a/src/app/services/chat.service.ts +++ b/src/app/services/chat.service.ts @@ -17,7 +17,7 @@ export class ChatService { login(loginToken: string): Promise { console.log('MATRIXCS'); - console.log(matrixcs); + // console.log(matrixcs); // console.log('SDK'); // console.log(sdk); return this.http.post( @@ -31,15 +31,15 @@ export class ChatService { console.log('LOGGED TO CHAT'); console.log(res); - const client = matrixcs.createClient({ - baseUrl: "http://localhost:8008", - accessToken: res.access_token, - userId: res.user_id - }); + // const client = matrixcs.createClient({ + // baseUrl: "http://localhost:8008", + // accessToken: res.access_token, + // userId: res.user_id + // }); - client.publicRooms(function (err, data) { - console.log("Public Rooms: %s", JSON.stringify(data)); - }); + // client.publicRooms(function (err, data) { + // console.log("Public Rooms: %s", JSON.stringify(data)); + // }); }); } } diff --git a/src/app/shared/auth/auth.guard.ts b/src/app/shared/auth/auth.guard.ts deleted file mode 100644 index 8d01c3c..0000000 --- a/src/app/shared/auth/auth.guard.ts +++ /dev/null @@ -1,20 +0,0 @@ -import { Injectable } from '@angular/core'; -import { CanActivate, Router } from '@angular/router'; -import { OAuthService } from 'angular-oauth2-oidc'; - -@Injectable() -export class AuthGuard implements CanActivate { - constructor(private router: Router, private oauthService: OAuthService) {} - - canActivate(): boolean { - if ( - this.oauthService.hasValidAccessToken() && - this.oauthService.hasValidIdToken() - ) { - return true; - } else { - this.router.navigate(['/home', { login: true }]); - return false; - } - } -} diff --git a/src/app/shared/date/date.component.ts b/src/app/shared/date/date.component.ts deleted file mode 100644 index 6eefdae..0000000 --- a/src/app/shared/date/date.component.ts +++ /dev/null @@ -1,38 +0,0 @@ -import { Component, Input, OnInit, OnChanges } from '@angular/core'; - -@Component({ - selector: 'date-component', - template: ` -
{{ day }}.{{ month }}.{{ year }} {{ hour }}:{{ minute }}
- ` -}) -export class DateComponent implements OnInit, OnChanges { - @Input() date: string; - - day; - month; - year; - hour; - minute; - - constructor() { - console.debug('ctrl'); - } - - ngOnInit() {} - - ngOnChanges(change) { - // if(change.date) { ... } - - console.debug('change', change); - - let date = new Date(this.date); - - this.day = date.getDate(); - this.month = date.getMonth() + 1; - this.year = date.getFullYear(); - - this.hour = date.getHours(); - this.minute = date.getMinutes(); - } -} diff --git a/src/app/shared/deactivation/LeaveComponentGuard.ts b/src/app/shared/deactivation/LeaveComponentGuard.ts deleted file mode 100644 index 18858d3..0000000 --- a/src/app/shared/deactivation/LeaveComponentGuard.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { - CanDeactivate, - ActivatedRouteSnapshot, - RouterStateSnapshot -} from '@angular/router'; - -export class LeaveComponentGuard implements CanDeactivate { - canDeactivate( - component: any, - route: ActivatedRouteSnapshot, - state: RouterStateSnapshot - ): Promise { - return component.canDeactivate(); - } -} diff --git a/src/app/shared/pipes/city.pipe.ts b/src/app/shared/pipes/city.pipe.ts deleted file mode 100644 index 3e7269c..0000000 --- a/src/app/shared/pipes/city.pipe.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { Pipe, PipeTransform } from '@angular/core'; - -@Pipe({ - name: 'city', - pure: true -}) -export class CityPipe implements PipeTransform { - transform(value: any, ...args: any[]): any { - let fmt = args[0]; // short, long - let short, long; - - switch (value) { - case 'Graz': - long = 'Flughafen Graz Thalerhof'; - short = 'GRZ'; - break; - case 'Hamburg': - long = 'Airport Hamburg Fuhlsbüttl Helmut Schmidt'; - short = 'HAM'; - break; - default: - long = short = 'ROM'; - } - - if (fmt == 'short') return short; - return long; - } -} diff --git a/src/app/shared/preload/custom-preloading.strategy.ts b/src/app/shared/preload/custom-preloading.strategy.ts deleted file mode 100644 index 4e64939..0000000 --- a/src/app/shared/preload/custom-preloading.strategy.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { PreloadingStrategy, Route } from '@angular/router'; -import { Observable } from 'rxjs'; - -export class CustomPreloadingStrategy implements PreloadingStrategy { - preload(route: Route, fn: () => Observable): Observable { - //return Observable.of(true).delay(7000).flatMap(_ => fn()); - - if (true) { - return fn(); - } - } -} diff --git a/src/app/shared/shared.module.ts b/src/app/shared/shared.module.ts deleted file mode 100644 index 3d66239..0000000 --- a/src/app/shared/shared.module.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { NgModule, ModuleWithProviders } from '@angular/core'; -import { FormsModule } from '@angular/forms'; -import { CommonModule } from '@angular/common'; -import { CityPipe } from './pipes/city.pipe'; -import { CityValidatorDirective } from './validation/city.validator'; -import { RoundTrip } from './validation/roundtrip.validator'; -import { AsyncCityValidatorDirective } from './validation/async-city.validator'; -import { DateComponent } from './date/date.component'; -import { AuthGuard } from './auth/auth.guard'; -import { LeaveComponentGuard } from './deactivation/LeaveComponentGuard'; -import { CustomPreloadingStrategy } from './preload/custom-preloading.strategy'; - -@NgModule({ - imports: [ - FormsModule, // [(ngModel)] - CommonModule // ngFor, ngIf, ngStyle, ngClass, date, json - ], - providers: [], - declarations: [ - CityPipe, - CityValidatorDirective, - AsyncCityValidatorDirective, - RoundTrip, - DateComponent - ], - exports: [ - CityPipe, - CityValidatorDirective, - AsyncCityValidatorDirective, - RoundTrip, - DateComponent - ] -}) -export class SharedModule { - static forRoot(): ModuleWithProviders { - return { - providers: [AuthGuard, LeaveComponentGuard, CustomPreloadingStrategy], - ngModule: SharedModule - }; - } -} diff --git a/src/app/shared/validation/async-city.validator.ts b/src/app/shared/validation/async-city.validator.ts deleted file mode 100644 index b11d546..0000000 --- a/src/app/shared/validation/async-city.validator.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Directive } from '@angular/core'; -import { NG_ASYNC_VALIDATORS, AbstractControl } from '@angular/forms'; - -@Directive({ - selector: 'input[async-city]', - providers: [ - { - provide: NG_ASYNC_VALIDATORS, - useExisting: AsyncCityValidatorDirective, - multi: true - } - ] -}) -export class AsyncCityValidatorDirective { - validate(ctrl: AbstractControl): Promise { - return new Promise((resolve: Function) => { - setTimeout(() => { - if (ctrl.value == 'Graz' || ctrl.value == 'Hamburg') { - resolve({}); - return; - } - - resolve({ 'async-city': false }); - }, 100); - }); - } -} diff --git a/src/app/shared/validation/city.validator.ts b/src/app/shared/validation/city.validator.ts deleted file mode 100644 index 9ce9aea..0000000 --- a/src/app/shared/validation/city.validator.ts +++ /dev/null @@ -1,50 +0,0 @@ -import { Directive, Input, Attribute } from '@angular/core'; -import { - NG_VALIDATORS, - Validator, - AbstractControl, - FormGroup -} from '@angular/forms'; - -@Directive({ - selector: 'input[city]', // - providers: [ - { - provide: NG_VALIDATORS, - useExisting: CityValidatorDirective, - multi: true - } - ] -}) -export class CityValidatorDirective implements Validator { - // @Input() city: string; - - constructor(@Attribute('city') private city: string) {} - - validate(c: AbstractControl): any { - let formGroup = c.root; - let otherValueCtrl = formGroup.controls['to']; - - if (!otherValueCtrl) return {}; - - let otherValue = otherValueCtrl.value; - - if (otherValue == c.value) { - return { - city: 'rundflug' - }; - } - - if (!this.city) return {}; - - let allowed = this.city.split(','); //['Graz', 'Hamburg', 'Wien', 'Frankfurt']; - - if (allowed.indexOf(c.value) == -1) { - return { - city: true - }; - } - - return {}; - } -} diff --git a/src/app/shared/validation/roundtrip.validator.ts b/src/app/shared/validation/roundtrip.validator.ts deleted file mode 100644 index 319a132..0000000 --- a/src/app/shared/validation/roundtrip.validator.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { Directive } from '@angular/core'; -import { - FormGroup, - Validator, - AbstractControl, - NG_VALIDATORS, - FormGroupDirective -} from '@angular/forms'; - -@Directive({ - selector: 'form[round-trip]', - providers: [{ provide: NG_VALIDATORS, useExisting: RoundTrip, multi: true }] -}) -export class RoundTrip implements Validator { - validate(control: AbstractControl): any { - let formGroup = control; - let fromCtrl = formGroup.controls['from']; - let toCtrl = formGroup.controls['to']; - - if (!fromCtrl || !toCtrl) return {}; - - let from = fromCtrl.value; - let to = toCtrl.value; - - if (from == to) { - return { - 'round-trip': { - city: from - } - }; - } - return {}; - } -}