2021-08-17 14:42:53 +02:00
|
|
|
import { catchError } from 'rxjs/operators'
|
2020-11-09 16:25:27 +01:00
|
|
|
import { HttpClient } from '@angular/common/http'
|
2021-08-17 14:42:53 +02:00
|
|
|
import { Injectable } from '@angular/core'
|
2020-11-09 16:25:27 +01:00
|
|
|
import { ScopedToken } from '@shared/models/users/user-scoped-token'
|
2021-08-17 14:42:53 +02:00
|
|
|
import { environment } from '../../../environments/environment'
|
2020-11-09 16:25:27 +01:00
|
|
|
import { RestExtractor } from '../rest'
|
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ScopedTokensService {
|
|
|
|
private static BASE_SCOPED_TOKENS_URL = environment.apiUrl + '/api/v1/users/scoped-tokens'
|
|
|
|
|
|
|
|
constructor (
|
|
|
|
private authHttp: HttpClient,
|
|
|
|
private restExtractor: RestExtractor
|
|
|
|
) {}
|
|
|
|
|
|
|
|
getScopedTokens () {
|
|
|
|
return this.authHttp
|
|
|
|
.get<ScopedToken>(ScopedTokensService.BASE_SCOPED_TOKENS_URL)
|
|
|
|
.pipe(
|
|
|
|
catchError(res => this.restExtractor.handleError(res))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
renewScopedTokens () {
|
|
|
|
return this.authHttp
|
|
|
|
.post<ScopedToken>(ScopedTokensService.BASE_SCOPED_TOKENS_URL, {})
|
|
|
|
.pipe(
|
|
|
|
catchError(res => this.restExtractor.handleError(res))
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|