diff options
Diffstat (limited to 'client/src/app/core/scoped-tokens')
-rw-r--r-- | client/src/app/core/scoped-tokens/index.ts | 1 | ||||
-rw-r--r-- | client/src/app/core/scoped-tokens/scoped-tokens.service.ts | 33 |
2 files changed, 34 insertions, 0 deletions
diff --git a/client/src/app/core/scoped-tokens/index.ts b/client/src/app/core/scoped-tokens/index.ts new file mode 100644 index 000000000..c9a48ffcd --- /dev/null +++ b/client/src/app/core/scoped-tokens/index.ts | |||
@@ -0,0 +1 @@ | |||
export * from './scoped-tokens.service' | |||
diff --git a/client/src/app/core/scoped-tokens/scoped-tokens.service.ts b/client/src/app/core/scoped-tokens/scoped-tokens.service.ts new file mode 100644 index 000000000..8e3697c31 --- /dev/null +++ b/client/src/app/core/scoped-tokens/scoped-tokens.service.ts | |||
@@ -0,0 +1,33 @@ | |||
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 | } | ||