From ebf0541385d833e2b68e51303ddfe69ab5ab8d02 Mon Sep 17 00:00:00 2001 From: Jesse Lucas Date: Fri, 13 Mar 2020 22:11:05 -0400 Subject: [PATCH] start of CSRF --- src/app/app.component.ts | 14 +++++++++++++- src/app/app.module.ts | 16 +++++++++++++++- src/index.html | 6 +++++- 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/app/app.component.ts b/src/app/app.component.ts index fed51e5c5..38bbc2bcd 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,4 +1,5 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; +import { SystemConfigService } from './system-config.service'; @Component({ selector: 'app-root', @@ -7,4 +8,15 @@ import { Component } from '@angular/core'; }) export class AppComponent { title = 'Tech UI'; + + constructor(private systemConfigService: SystemConfigService) { } + + ngOnInit(): void { + console.log("app component init"); + this.systemConfigService.getSystemConfig().subscribe( + x => console.log('Observer got a next value: ' + x), + err => console.error('Observer got an error: ' + err), + () => console.log('Observer got a complete notification') + ); + } } diff --git a/src/app/app.module.ts b/src/app/app.module.ts index 1aaf6daf3..91ad36bb9 100644 --- a/src/app/app.module.ts +++ b/src/app/app.module.ts @@ -1,5 +1,6 @@ import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; +import { HttpClientModule, HttpClientXsrfModule } from '@angular/common/http'; import { MatTableModule } from '@angular/material/table'; import { MatPaginatorModule } from '@angular/material/paginator'; @@ -13,7 +14,12 @@ import { StatusListComponent } from './status-list/status-list.component'; import { FolderListComponent } from './folder-list/folder-list.component'; import { DeviceListComponent } from './device-list/device-list.component'; import { StatusToggleComponent } from './status-toggle/status-toggle.component'; +import { DeviceListDataSource } from './device-list/device-list-datasource'; +const deviceID = (): String => { + const dID: String = globalThis.metadata['deviceID']; + return dID.substring(0, 5) +} @NgModule({ declarations: [ @@ -30,9 +36,17 @@ import { StatusToggleComponent } from './status-toggle/status-toggle.component'; MatTableModule, MatPaginatorModule, MatSortModule, - MatButtonToggleModule + MatButtonToggleModule, + HttpClientModule, + HttpClientXsrfModule.withOptions({ + headerName: 'X-CSRF-Token-' + deviceID(), + cookieName: 'CSRF-Token-' + deviceID(), + }) ], providers: [], bootstrap: [AppComponent] }) + export class AppModule { } + + diff --git a/src/index.html b/src/index.html index 96b91058b..df34f6890 100644 --- a/src/index.html +++ b/src/index.html @@ -1,5 +1,6 @@ + TechUi @@ -8,8 +9,11 @@ + + - + + \ No newline at end of file