aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/app/users/shared/auth.service.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-27 17:49:18 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-27 17:49:18 +0200
commit4fd8aa327004b27530fd96bdde5df60e6745a1f6 (patch)
treee3b21282c641d50ea62e227c6ce3e7e740fec860 /client/app/users/shared/auth.service.ts
parentccf6ed16f1eeb05b77103bd44bc06ccbbbba9bdd (diff)
downloadPeerTube-4fd8aa327004b27530fd96bdde5df60e6745a1f6.tar.gz
PeerTube-4fd8aa327004b27530fd96bdde5df60e6745a1f6.tar.zst
PeerTube-4fd8aa327004b27530fd96bdde5df60e6745a1f6.zip
Alphabetical
Diffstat (limited to 'client/app/users/shared/auth.service.ts')
-rw-r--r--client/app/users/shared/auth.service.ts60
1 files changed, 30 insertions, 30 deletions
diff --git a/client/app/users/shared/auth.service.ts b/client/app/users/shared/auth.service.ts
index b1da94436..d63fe38f3 100644
--- a/client/app/users/shared/auth.service.ts
+++ b/client/app/users/shared/auth.service.ts
@@ -7,14 +7,14 @@ import { User } from './user.model';
7 7
8@Injectable() 8@Injectable()
9export class AuthService { 9export class AuthService {
10 private static BASE_LOGIN_URL = '/api/v1/users/token';
11 private static BASE_CLIENT_URL = '/api/v1/users/client'; 10 private static BASE_CLIENT_URL = '/api/v1/users/client';
11 private static BASE_LOGIN_URL = '/api/v1/users/token';
12 12
13 loginChangedSource: Observable<AuthStatus>; 13 loginChangedSource: Observable<AuthStatus>;
14 14
15 private loginChanged: Subject<AuthStatus>;
16 private clientId: string; 15 private clientId: string;
17 private clientSecret: string; 16 private clientSecret: string;
17 private loginChanged: Subject<AuthStatus>;
18 18
19 constructor(private http: Http) { 19 constructor(private http: Http) {
20 this.loginChanged = new Subject<AuthStatus>(); 20 this.loginChanged = new Subject<AuthStatus>();
@@ -37,40 +37,14 @@ export class AuthService {
37 ); 37 );
38 } 38 }
39 39
40 login(username: string, password: string) { 40 getAuthRequestOptions(): RequestOptions {
41 let body = new URLSearchParams(); 41 return new RequestOptions({ headers: this.getRequestHeader() });
42 body.set('client_id', this.clientId);
43 body.set('client_secret', this.clientSecret);
44 body.set('response_type', 'code');
45 body.set('grant_type', 'password');
46 body.set('scope', 'upload');
47 body.set('username', username);
48 body.set('password', password);
49
50 let headers = new Headers();
51 headers.append('Content-Type', 'application/x-www-form-urlencoded');
52
53 let options = {
54 headers: headers
55 };
56
57 return this.http.post(AuthService.BASE_LOGIN_URL, body.toString(), options)
58 .map(res => res.json())
59 .catch(this.handleError);
60 }
61
62 logout() {
63 // TODO make HTTP request
64 } 42 }
65 43
66 getRequestHeader() { 44 getRequestHeader() {
67 return new Headers({ 'Authorization': `${this.getTokenType()} ${this.getToken()}` }); 45 return new Headers({ 'Authorization': `${this.getTokenType()} ${this.getToken()}` });
68 } 46 }
69 47
70 getAuthRequestOptions(): RequestOptions {
71 return new RequestOptions({ headers: this.getRequestHeader() });
72 }
73
74 getToken() { 48 getToken() {
75 return localStorage.getItem('access_token'); 49 return localStorage.getItem('access_token');
76 } 50 }
@@ -97,6 +71,32 @@ export class AuthService {
97 } 71 }
98 } 72 }
99 73
74 login(username: string, password: string) {
75 let body = new URLSearchParams();
76 body.set('client_id', this.clientId);
77 body.set('client_secret', this.clientSecret);
78 body.set('response_type', 'code');
79 body.set('grant_type', 'password');
80 body.set('scope', 'upload');
81 body.set('username', username);
82 body.set('password', password);
83
84 let headers = new Headers();
85 headers.append('Content-Type', 'application/x-www-form-urlencoded');
86
87 let options = {
88 headers: headers
89 };
90
91 return this.http.post(AuthService.BASE_LOGIN_URL, body.toString(), options)
92 .map(res => res.json())
93 .catch(this.handleError);
94 }
95
96 logout() {
97 // TODO make HTTP request
98 }
99
100 setStatus(status: AuthStatus) { 100 setStatus(status: AuthStatus) {
101 this.loginChanged.next(status); 101 this.loginChanged.next(status);
102 } 102 }