aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src/app/shared/auth
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
committerChocobozzz <florian.bigard@gmail.com>2017-06-16 14:32:15 +0200
commitdf98563e2104b82b119c00a3cd83cd0dc1242d25 (patch)
treea9720bf01bac9ad5646bd3d3c9bc7653617afdad /client/src/app/shared/auth
parent46757b477c1adb5f98060d15998a3852e18902a6 (diff)
downloadPeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.gz
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.tar.zst
PeerTube-df98563e2104b82b119c00a3cd83cd0dc1242d25.zip
Use typescript standard and lint all files
Diffstat (limited to 'client/src/app/shared/auth')
-rw-r--r--client/src/app/shared/auth/auth-http.service.ts82
-rw-r--r--client/src/app/shared/auth/index.ts2
2 files changed, 42 insertions, 42 deletions
diff --git a/client/src/app/shared/auth/auth-http.service.ts b/client/src/app/shared/auth/auth-http.service.ts
index c4114aa02..0fbaab0a8 100644
--- a/client/src/app/shared/auth/auth-http.service.ts
+++ b/client/src/app/shared/auth/auth-http.service.ts
@@ -1,4 +1,4 @@
1import { Injectable } from '@angular/core'; 1import { Injectable } from '@angular/core'
2import { 2import {
3 ConnectionBackend, 3 ConnectionBackend,
4 Headers, 4 Headers,
@@ -9,79 +9,79 @@ import {
9 RequestOptionsArgs, 9 RequestOptionsArgs,
10 Response, 10 Response,
11 XHRBackend 11 XHRBackend
12} from '@angular/http'; 12} from '@angular/http'
13import { Observable } from 'rxjs/Observable'; 13import { Observable } from 'rxjs/Observable'
14 14
15import { AuthService } from '../../core'; 15import { AuthService } from '../../core'
16 16
17@Injectable() 17@Injectable()
18export class AuthHttp extends Http { 18export class AuthHttp extends Http {
19 constructor(backend: ConnectionBackend, defaultOptions: RequestOptions, private authService: AuthService) { 19 constructor (backend: ConnectionBackend, defaultOptions: RequestOptions, private authService: AuthService) {
20 super(backend, defaultOptions); 20 super(backend, defaultOptions)
21 } 21 }
22 22
23 request(url: string | Request, options?: RequestOptionsArgs): Observable<Response> { 23 request (url: string | Request, options?: RequestOptionsArgs): Observable<Response> {
24 if (!options) options = {}; 24 if (!options) options = {}
25 25
26 options.headers = new Headers(); 26 options.headers = new Headers()
27 this.setAuthorizationHeader(options.headers); 27 this.setAuthorizationHeader(options.headers)
28 28
29 return super.request(url, options) 29 return super.request(url, options)
30 .catch((err) => { 30 .catch((err) => {
31 if (err.status === 401) { 31 if (err.status === 401) {
32 return this.handleTokenExpired(url, options); 32 return this.handleTokenExpired(url, options)
33 } 33 }
34 34
35 return Observable.throw(err); 35 return Observable.throw(err)
36 }); 36 })
37 } 37 }
38 38
39 delete(url: string, options?: RequestOptionsArgs): Observable<Response> { 39 delete (url: string, options?: RequestOptionsArgs): Observable<Response> {
40 if (!options) options = {}; 40 if (!options) options = {}
41 options.method = RequestMethod.Delete; 41 options.method = RequestMethod.Delete
42 42
43 return this.request(url, options); 43 return this.request(url, options)
44 } 44 }
45 45
46 get(url: string, options?: RequestOptionsArgs): Observable<Response> { 46 get (url: string, options?: RequestOptionsArgs): Observable<Response> {
47 if (!options) options = {}; 47 if (!options) options = {}
48 options.method = RequestMethod.Get; 48 options.method = RequestMethod.Get
49 49
50 return this.request(url, options); 50 return this.request(url, options)
51 } 51 }
52 52
53 post(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> { 53 post (url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
54 if (!options) options = {}; 54 if (!options) options = {}
55 options.method = RequestMethod.Post; 55 options.method = RequestMethod.Post
56 options.body = body; 56 options.body = body
57 57
58 return this.request(url, options); 58 return this.request(url, options)
59 } 59 }
60 60
61 put(url: string, body: any, options?: RequestOptionsArgs): Observable<Response> { 61 put (url: string, body: any, options?: RequestOptionsArgs): Observable<Response> {
62 if (!options) options = {}; 62 if (!options) options = {}
63 options.method = RequestMethod.Put; 63 options.method = RequestMethod.Put
64 options.body = body; 64 options.body = body
65 65
66 return this.request(url, options); 66 return this.request(url, options)
67 } 67 }
68 68
69 private handleTokenExpired(url: string | Request, options: RequestOptionsArgs) { 69 private handleTokenExpired (url: string | Request, options: RequestOptionsArgs) {
70 return this.authService.refreshAccessToken() 70 return this.authService.refreshAccessToken()
71 .flatMap(() => { 71 .flatMap(() => {
72 this.setAuthorizationHeader(options.headers); 72 this.setAuthorizationHeader(options.headers)
73 73
74 return super.request(url, options); 74 return super.request(url, options)
75 }); 75 })
76 } 76 }
77 77
78 private setAuthorizationHeader(headers: Headers) { 78 private setAuthorizationHeader (headers: Headers) {
79 headers.set('Authorization', this.authService.getRequestHeaderValue()); 79 headers.set('Authorization', this.authService.getRequestHeaderValue())
80 } 80 }
81} 81}
82 82
83export function useFactory(backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) { 83export function useFactory (backend: XHRBackend, defaultOptions: RequestOptions, authService: AuthService) {
84 return new AuthHttp(backend, defaultOptions, authService); 84 return new AuthHttp(backend, defaultOptions, authService)
85} 85}
86 86
87export const AUTH_HTTP_PROVIDERS = [ 87export const AUTH_HTTP_PROVIDERS = [
@@ -89,5 +89,5 @@ export const AUTH_HTTP_PROVIDERS = [
89 provide: AuthHttp, 89 provide: AuthHttp,
90 useFactory, 90 useFactory,
91 deps: [ XHRBackend, RequestOptions, AuthService ] 91 deps: [ XHRBackend, RequestOptions, AuthService ]
92 }, 92 }
93]; 93]
diff --git a/client/src/app/shared/auth/index.ts b/client/src/app/shared/auth/index.ts
index c488aed69..0f2bfb0d6 100644
--- a/client/src/app/shared/auth/index.ts
+++ b/client/src/app/shared/auth/index.ts
@@ -1 +1 @@
export * from './auth-http.service'; export * from './auth-http.service'