Skip to content

Commit

Permalink
Upgrade to Identity Server 4 version 2.1 (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
elanderson authored Jan 11, 2018
1 parent 60ebf23 commit 62c05b7
Show file tree
Hide file tree
Showing 21 changed files with 158,742 additions and 129,258 deletions.
2 changes: 1 addition & 1 deletion ApiApp/ApiApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions ClientApp/ClientApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityModel" Version="2.15.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="IdentityModel" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.3" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions ClientApp/ClientApp/app/app.module.shared.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { HttpClientModule } from '@angular/common/http';
import { RouterModule } from '@angular/router';

import { AppComponent } from './components/app/app.component'
Expand All @@ -26,7 +26,7 @@ import { AuthService } from './components/services/auth.service';
imports: [
AuthModule.forRoot(),
CommonModule,
HttpModule,
HttpClientModule,
FormsModule,
RouterModule.forRoot([
{ path: '', redirectTo: 'home', pathMatch: 'full' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class FetchDataComponent {

constructor(authService: AuthService, @Inject('API_URL') apiUrl: string) {
authService.get(apiUrl + 'SampleData/WeatherForecasts').subscribe(result => {
this.forecasts = result.json() as WeatherForecast[];
this.forecasts = result as WeatherForecast[];
}, error => console.error(error));
}
}
Expand Down
48 changes: 16 additions & 32 deletions ClientApp/ClientApp/app/components/services/auth.service.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Injectable, Component, OnInit, OnDestroy, Inject } from '@angular/core';
import { Http, Headers, RequestOptions, Response } from '@angular/http';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Observable } from 'rxjs/Rx';
import { Subscription } from 'rxjs/Subscription';

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

constructor(public oidcSecurityService: OidcSecurityService,
private http: Http,
private http: HttpClient,
@Inject('ORIGIN_URL') originUrl: string,
@Inject('IDENTITY_URL') identityUrl: string
) {
Expand Down Expand Up @@ -77,52 +77,36 @@ export class AuthService implements OnInit, OnDestroy {
}
}

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

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

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

post(url: string, data: any, options?: RequestOptions): Observable<Response> {
post(url: string, data: any): Observable<any> {
const body = JSON.stringify(data);
return this.http.post(url, body, this.setRequestOptions(options));
}

private setRequestOptions(options?: RequestOptions | null) {
if (options) {
this.appendAuthHeader(options.headers);
}
else {
options = new RequestOptions({ headers: this.getHeaders(), body: "" });
}
return options;
return this.http.post<any>(url, body, { headers: this.getHeaders() });
}

private getHeaders() {
const headers = new Headers();
headers.append('Content-Type', 'application/json');
this.appendAuthHeader(headers);
return headers;
let headers = new HttpHeaders();
headers = headers.set('Content-Type', 'application/json');
return this.appendAuthHeader(headers);
}

private appendAuthHeader(headers?: Headers | null) {

if (headers == null) headers = this.getHeaders();

private appendAuthHeader(headers: HttpHeaders) {
const token = this.oidcSecurityService.getToken();

if (token == '') return;
if (token === '') return headers;

const tokenValue = 'Bearer ' + token;
headers.append('Authorization', tokenValue);
return headers.set('Authorization', tokenValue);
}


}
2 changes: 1 addition & 1 deletion ClientApp/ClientApp/boot.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default createServerRenderer(params => {
return platformDynamicServer(providers).bootstrapModule(AppModule).then(moduleRef => {
const appRef: ApplicationRef = moduleRef.injector.get(ApplicationRef);
const state = moduleRef.injector.get(PlatformState);
const zone = moduleRef.injector.get(NgZone);
const zone: NgZone = moduleRef.injector.get(NgZone);

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

0 comments on commit 62c05b7

Please sign in to comment.