11import { 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' ;
33import { Observable } from 'rxjs/Rx' ;
44import { 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}
0 commit comments