]>
Commit | Line | Data |
---|---|---|
5beb89f2 RK |
1 | import { Injectable } from '@angular/core' |
2 | import { HttpClient } from '@angular/common/http' | |
3 | import { environment } from '../../../environments/environment' | |
4 | import { AuthService } from '../auth' | |
5 | import { ScopedToken } from '@shared/models/users/user-scoped-token' | |
6 | import { catchError } from 'rxjs/operators' | |
7 | import { RestExtractor } from '../rest' | |
8 | ||
9 | @Injectable() | |
10 | export class ScopedTokensService { | |
11 | private static BASE_SCOPED_TOKENS_URL = environment.apiUrl + '/api/v1/users/scoped-tokens' | |
12 | ||
13 | constructor ( | |
14 | private authHttp: HttpClient, | |
15 | private restExtractor: RestExtractor | |
16 | ) {} | |
17 | ||
18 | getScopedTokens () { | |
19 | return this.authHttp | |
20 | .get<ScopedToken>(ScopedTokensService.BASE_SCOPED_TOKENS_URL) | |
21 | .pipe( | |
22 | catchError(res => this.restExtractor.handleError(res)) | |
23 | ) | |
24 | } | |
25 | ||
26 | renewScopedTokens () { | |
27 | return this.authHttp | |
28 | .post<ScopedToken>(ScopedTokensService.BASE_SCOPED_TOKENS_URL, {}) | |
29 | .pipe( | |
30 | catchError(res => this.restExtractor.handleError(res)) | |
31 | ) | |
32 | } | |
33 | } |