-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from FlyersWeb/noSecretStored
Secret is not stored anymore
- Loading branch information
Showing
19 changed files
with
266 additions
and
274 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,15 @@ | ||
import { NgModule } from '@angular/core'; | ||
import { Routes, RouterModule } from '@angular/router'; | ||
import { LoginComponent } from './login/login.component'; | ||
import { HelloComponent } from './hello/hello.component'; | ||
|
||
import { NgModule } from '@angular/core' | ||
import { Routes, RouterModule } from '@angular/router' | ||
import { LoginComponent } from './login/login.component' | ||
import { HelloComponent } from './hello/hello.component' | ||
|
||
const routes: Routes = [ | ||
{ path: '', component: LoginComponent}, | ||
{ path: 'hello', component: HelloComponent} | ||
]; | ||
{ path: '', component: LoginComponent }, | ||
{ path: 'hello', component: HelloComponent } | ||
] | ||
|
||
@NgModule({ | ||
imports: [RouterModule.forRoot( | ||
routes | ||
)], | ||
imports: [RouterModule.forRoot(routes)], | ||
exports: [RouterModule] | ||
}) | ||
export class AppRoutingModule { } | ||
export class AppRoutingModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,18 @@ | ||
import { TestBed, async } from '@angular/core/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { AppComponent } from './app.component'; | ||
import { TestBed, async } from '@angular/core/testing' | ||
import { RouterTestingModule } from '@angular/router/testing' | ||
import { AppComponent } from './app.component' | ||
|
||
describe('AppComponent', () => { | ||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
RouterTestingModule | ||
], | ||
declarations: [ | ||
AppComponent | ||
], | ||
}).compileComponents(); | ||
})); | ||
imports: [RouterTestingModule], | ||
declarations: [AppComponent] | ||
}).compileComponents() | ||
})) | ||
|
||
it('should create the app', () => { | ||
const fixture = TestBed.createComponent(AppComponent); | ||
const app = fixture.debugElement.componentInstance; | ||
expect(app).toBeTruthy(); | ||
}); | ||
|
||
}); | ||
const fixture = TestBed.createComponent(AppComponent) | ||
const app = fixture.debugElement.componentInstance | ||
expect(app).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { Component } from '@angular/core'; | ||
import { Component } from '@angular/core' | ||
|
||
@Component({ | ||
selector: 'app-root', | ||
templateUrl: './app.component.html', | ||
styleUrls: ['./app.component.css'] | ||
}) | ||
export class AppComponent { | ||
title = 'Angular Symfony'; | ||
title = 'Angular Symfony' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,23 @@ | ||
import { BrowserModule } from '@angular/platform-browser'; | ||
import { NgModule } from '@angular/core'; | ||
import { BrowserModule } from '@angular/platform-browser' | ||
import { NgModule } from '@angular/core' | ||
|
||
import { AppRoutingModule } from './app-routing.module'; | ||
import { ReactiveFormsModule } from '@angular/forms'; | ||
import { HttpClientModule } from '@angular/common/http'; | ||
import { AppComponent } from './app.component'; | ||
import { LoginComponent } from './login/login.component'; | ||
import { HelloComponent } from './hello/hello.component'; | ||
import { httpInterceptorProviders } from './http-interceptor'; | ||
import { AppRoutingModule } from './app-routing.module' | ||
import { ReactiveFormsModule } from '@angular/forms' | ||
import { HttpClientModule } from '@angular/common/http' | ||
import { AppComponent } from './app.component' | ||
import { LoginComponent } from './login/login.component' | ||
import { HelloComponent } from './hello/hello.component' | ||
import { httpInterceptorProviders } from './http-interceptor' | ||
|
||
@NgModule({ | ||
declarations: [ | ||
AppComponent, | ||
LoginComponent, | ||
HelloComponent | ||
], | ||
declarations: [AppComponent, LoginComponent, HelloComponent], | ||
imports: [ | ||
BrowserModule, | ||
AppRoutingModule, | ||
ReactiveFormsModule, | ||
HttpClientModule, | ||
], | ||
providers: [ | ||
httpInterceptorProviders | ||
HttpClientModule | ||
], | ||
providers: [httpInterceptorProviders], | ||
bootstrap: [AppComponent] | ||
}) | ||
export class AppModule { } | ||
export class AppModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,27 @@ | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing'; | ||
import { HttpClientTestingModule } from '@angular/common/http/testing'; | ||
import { RouterTestingModule } from '@angular/router/testing'; | ||
import { async, ComponentFixture, TestBed } from '@angular/core/testing' | ||
import { HttpClientTestingModule } from '@angular/common/http/testing' | ||
import { RouterTestingModule } from '@angular/router/testing' | ||
|
||
import { HelloComponent } from './hello.component'; | ||
import { HelloComponent } from './hello.component' | ||
|
||
describe('HelloComponent', () => { | ||
let component: HelloComponent; | ||
let fixture: ComponentFixture<HelloComponent>; | ||
let component: HelloComponent | ||
let fixture: ComponentFixture<HelloComponent> | ||
|
||
beforeEach(async(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [ | ||
HttpClientTestingModule, | ||
RouterTestingModule, | ||
], | ||
declarations: [ HelloComponent ] | ||
}) | ||
.compileComponents(); | ||
})); | ||
imports: [HttpClientTestingModule, RouterTestingModule], | ||
declarations: [HelloComponent] | ||
}).compileComponents() | ||
})) | ||
|
||
beforeEach(() => { | ||
fixture = TestBed.createComponent(HelloComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
fixture = TestBed.createComponent(HelloComponent) | ||
component = fixture.componentInstance | ||
fixture.detectChanges() | ||
}) | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); | ||
expect(component).toBeTruthy() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,47 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { Component, OnInit } from '@angular/core' | ||
import { Observable } from 'rxjs' | ||
|
||
import { WSSEService } from '../wsse.service'; | ||
import { HttpErrorResponse } from '@angular/common/http'; | ||
import { Router } from '@angular/router'; | ||
import { TokenService } from '../token.service'; | ||
import { WSSEService } from '../wsse.service' | ||
import { HttpErrorResponse } from '@angular/common/http' | ||
import { Router } from '@angular/router' | ||
import { TokenService } from '../token.service' | ||
|
||
@Component({ | ||
selector: 'app-hello', | ||
templateUrl: './hello.component.html', | ||
styleUrls: ['./hello.component.css'] | ||
}) | ||
export class HelloComponent implements OnInit { | ||
$hello: Observable<{ hello?: string }> | ||
helloMessage: string | ||
|
||
$hello: Observable<{ hello?: string }>; | ||
helloMessage: string; | ||
|
||
constructor( | ||
constructor ( | ||
private wsseService: WSSEService, | ||
private tokenService: TokenService, | ||
private router: Router, | ||
) { } | ||
private router: Router | ||
) {} | ||
|
||
ngOnInit() { | ||
ngOnInit () { | ||
// Example API call showing an Hello World | ||
this.$hello = this.wsseService.getHello(); | ||
this.$hello = this.wsseService.getHello() | ||
|
||
this.$hello.subscribe( | ||
// Show API response | ||
({ hello }) => { | ||
console.log(`Received from server ${hello}`); | ||
this.helloMessage = hello; | ||
console.log(`Received from server ${hello}`) | ||
this.helloMessage = hello | ||
}, | ||
// Log error message and redirect to login | ||
(error: HttpErrorResponse) => { | ||
console.error(error); | ||
console.error(error) | ||
if (error.status === 401) { | ||
return this.router.navigate(['']); | ||
return this.router.navigate(['']) | ||
} | ||
}); | ||
} | ||
) | ||
} | ||
|
||
onGoBack() { | ||
return this.router.navigate(['']); | ||
onGoBack () { | ||
return this.router.navigate(['']) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import { HTTP_INTERCEPTORS } from '@angular/common/http'; | ||
import { HTTP_INTERCEPTORS } from '@angular/common/http' | ||
|
||
import { WSSEInterceptor } from './wsse-interceptor'; | ||
import { WSSEInterceptor } from './wsse-interceptor' | ||
|
||
/** Http interceptor providers in outside-in order */ | ||
export const httpInterceptorProviders = [ | ||
{ provide: HTTP_INTERCEPTORS, useClass: WSSEInterceptor, multi: true }, | ||
]; | ||
{ provide: HTTP_INTERCEPTORS, useClass: WSSEInterceptor, multi: true } | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,25 @@ | ||
import { TokenService } from '../token.service'; | ||
import { Injectable } from '@angular/core'; | ||
import { HttpInterceptor, HttpRequest, HttpHandler } from '@angular/common/http'; | ||
import { TokenService } from '../token.service' | ||
import { Injectable } from '@angular/core' | ||
import { HttpInterceptor, HttpRequest, HttpHandler } from '@angular/common/http' | ||
|
||
@Injectable() | ||
export class WSSEInterceptor implements HttpInterceptor { | ||
constructor (private tokenService: TokenService) {} | ||
|
||
constructor(private tokenService: TokenService) {} | ||
|
||
intercept(req: HttpRequest<any>, next: HttpHandler) { | ||
let authToken = this.tokenService.getAuthorizationToken(); | ||
intercept (req: HttpRequest<any>, next: HttpHandler) { | ||
let authToken = this.tokenService.getAuthorizationToken() | ||
|
||
if (authToken) { | ||
// Clone the request and replace the original headers with | ||
// cloned headers, updated with the authorization. | ||
// cloned headers, updated with the authorization. | ||
const authReq = req.clone({ | ||
headers: req.headers.set('X-WSSE', authToken) | ||
}); | ||
}) | ||
// send cloned request with header to the next handler. | ||
return next.handle(authReq); | ||
return next.handle(authReq) | ||
} else { | ||
// otherwise send request without token | ||
return next.handle(req); | ||
return next.handle(req) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.