Skip to content

Commit 62c05b7

Browse files
authored
Upgrade to Identity Server 4 version 2.1 (#26)
1 parent 60ebf23 commit 62c05b7

21 files changed

+158742
-129258
lines changed

ApiApp/ApiApp.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
</ItemGroup>
1111

1212
<ItemGroup>
13-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
13+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
1414
</ItemGroup>
1515

1616
</Project>

ClientApp/ClientApp.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
</PropertyGroup>
99

1010
<ItemGroup>
11-
<PackageReference Include="IdentityModel" Version="2.15.0" />
12-
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
11+
<PackageReference Include="IdentityModel" Version="3.0.0" />
12+
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
1313
</ItemGroup>
1414

1515
<ItemGroup>

ClientApp/ClientApp/app/app.module.shared.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { NgModule } from '@angular/core';
22
import { CommonModule } from '@angular/common';
33
import { FormsModule } from '@angular/forms';
4-
import { HttpModule } from '@angular/http';
4+
import { HttpClientModule } from '@angular/common/http';
55
import { RouterModule } from '@angular/router';
66

77
import { AppComponent } from './components/app/app.component'
@@ -26,7 +26,7 @@ import { AuthService } from './components/services/auth.service';
2626
imports: [
2727
AuthModule.forRoot(),
2828
CommonModule,
29-
HttpModule,
29+
HttpClientModule,
3030
FormsModule,
3131
RouterModule.forRoot([
3232
{ path: '', redirectTo: 'home', pathMatch: 'full' },

ClientApp/ClientApp/app/components/fetchdata/fetchdata.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class FetchDataComponent {
1010

1111
constructor(authService: AuthService, @Inject('API_URL') apiUrl: string) {
1212
authService.get(apiUrl + 'SampleData/WeatherForecasts').subscribe(result => {
13-
this.forecasts = result.json() as WeatherForecast[];
13+
this.forecasts = result as WeatherForecast[];
1414
}, error => console.error(error));
1515
}
1616
}

ClientApp/ClientApp/app/components/services/auth.service.ts

Lines changed: 16 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Injectable, Component, OnInit, OnDestroy, Inject } from '@angular/core';
2-
import { Http, Headers, RequestOptions, Response } from '@angular/http';
2+
import { HttpClient, HttpHeaders } from '@angular/common/http';
33
import { Observable } from 'rxjs/Rx';
44
import { Subscription } from 'rxjs/Subscription';
55

@@ -11,7 +11,7 @@ export class AuthService implements OnInit, OnDestroy {
1111
isAuthorized: boolean;
1212

1313
constructor(public oidcSecurityService: OidcSecurityService,
14-
private http: Http,
14+
private http: HttpClient,
1515
@Inject('ORIGIN_URL') originUrl: string,
1616
@Inject('IDENTITY_URL') identityUrl: string
1717
) {
@@ -77,52 +77,36 @@ export class AuthService implements OnInit, OnDestroy {
7777
}
7878
}
7979

80-
get(url: string, options?: RequestOptions): Observable<Response> {
81-
return this.http.get(url, this.setRequestOptions(options));
80+
get(url: string): Observable<any> {
81+
return this.http.get<any>(url, { headers: this.getHeaders() });
8282
}
8383

84-
put(url: string, data: any, options?: RequestOptions): Observable<Response> {
84+
put(url: string, data: any): Observable<any> {
8585
const body = JSON.stringify(data);
86-
return this.http.put(url, body, this.setRequestOptions(options));
86+
return this.http.put<any>(url, body, { headers: this.getHeaders() });
8787
}
8888

89-
delete(url: string, options?: RequestOptions): Observable<Response> {
90-
return this.http.delete(url, this.setRequestOptions(options));
89+
delete(url: string): Observable<any> {
90+
return this.http.delete<any>(url, { headers: this.getHeaders() });
9191
}
9292

93-
post(url: string, data: any, options?: RequestOptions): Observable<Response> {
93+
post(url: string, data: any): Observable<any> {
9494
const body = JSON.stringify(data);
95-
return this.http.post(url, body, this.setRequestOptions(options));
96-
}
97-
98-
private setRequestOptions(options?: RequestOptions | null) {
99-
if (options) {
100-
this.appendAuthHeader(options.headers);
101-
}
102-
else {
103-
options = new RequestOptions({ headers: this.getHeaders(), body: "" });
104-
}
105-
return options;
95+
return this.http.post<any>(url, body, { headers: this.getHeaders() });
10696
}
10797

10898
private getHeaders() {
109-
const headers = new Headers();
110-
headers.append('Content-Type', 'application/json');
111-
this.appendAuthHeader(headers);
112-
return headers;
99+
let headers = new HttpHeaders();
100+
headers = headers.set('Content-Type', 'application/json');
101+
return this.appendAuthHeader(headers);
113102
}
114103

115-
private appendAuthHeader(headers?: Headers | null) {
116-
117-
if (headers == null) headers = this.getHeaders();
118-
104+
private appendAuthHeader(headers: HttpHeaders) {
119105
const token = this.oidcSecurityService.getToken();
120106

121-
if (token == '') return;
107+
if (token === '') return headers;
122108

123109
const tokenValue = 'Bearer ' + token;
124-
headers.append('Authorization', tokenValue);
110+
return headers.set('Authorization', tokenValue);
125111
}
126-
127-
128112
}

ClientApp/ClientApp/boot.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export default createServerRenderer(params => {
2323
return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => {
2424
const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
2525
const state = moduleRef.injector.get(PlatformState);
26-
const zone = moduleRef.injector.get(NgZone);
26+
const zone: NgZone = moduleRef.injector.get(NgZone);
2727

2828
return new Promise<RenderResult>((resolve, reject) => {
2929
zone.onError.subscribe((errorInfo: any) => reject(errorInfo));

0 commit comments

Comments
 (0)