|
|
|
|
@ -1,3 +1,7 @@
@@ -1,3 +1,7 @@
|
|
|
|
|
import { AppIdService } from "jslib-common/abstractions/appId.service"; |
|
|
|
|
import { DeviceRequest } from "jslib-common/models/request/deviceRequest"; |
|
|
|
|
import { TokenRequestTwoFactor } from "jslib-common/models/request/identityToken/tokenRequestTwoFactor"; |
|
|
|
|
|
|
|
|
|
import { ApiService as ApiServiceAbstraction } from "../abstractions/api.service"; |
|
|
|
|
import { EnvironmentService } from "../abstractions/environment.service"; |
|
|
|
|
import { PlatformUtilsService } from "../abstractions/platformUtils.service"; |
|
|
|
|
@ -174,7 +178,6 @@ import { UserKeyResponse } from "../models/response/userKeyResponse";
@@ -174,7 +178,6 @@ import { UserKeyResponse } from "../models/response/userKeyResponse";
|
|
|
|
|
import { SendAccessView } from "../models/view/sendAccessView"; |
|
|
|
|
|
|
|
|
|
export class ApiService implements ApiServiceAbstraction { |
|
|
|
|
protected apiKeyRefresh: (clientId: string, clientSecret: string) => Promise<any>; |
|
|
|
|
private device: DeviceType; |
|
|
|
|
private deviceType: string; |
|
|
|
|
private isWebClient = false; |
|
|
|
|
@ -184,6 +187,7 @@ export class ApiService implements ApiServiceAbstraction {
@@ -184,6 +187,7 @@ export class ApiService implements ApiServiceAbstraction {
|
|
|
|
|
private tokenService: TokenService, |
|
|
|
|
private platformUtilsService: PlatformUtilsService, |
|
|
|
|
private environmentService: EnvironmentService, |
|
|
|
|
private appIdService: AppIdService, |
|
|
|
|
private logoutCallback: (expired: boolean) => Promise<void>, |
|
|
|
|
private customUserAgent: string = null |
|
|
|
|
) { |
|
|
|
|
@ -2332,20 +2336,6 @@ export class ApiService implements ApiServiceAbstraction {
@@ -2332,20 +2336,6 @@ export class ApiService implements ApiServiceAbstraction {
|
|
|
|
|
throw new Error("Cannot refresh token, no refresh token or api keys are stored"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected async doApiTokenRefresh(): Promise<void> { |
|
|
|
|
const clientId = await this.tokenService.getClientId(); |
|
|
|
|
const clientSecret = await this.tokenService.getClientSecret(); |
|
|
|
|
if ( |
|
|
|
|
Utils.isNullOrWhitespace(clientId) || |
|
|
|
|
Utils.isNullOrWhitespace(clientSecret) || |
|
|
|
|
this.apiKeyRefresh == null |
|
|
|
|
) { |
|
|
|
|
throw new Error(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await this.apiKeyRefresh(clientId, clientSecret); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected async doRefreshToken(): Promise<void> { |
|
|
|
|
const refreshToken = await this.tokenService.getRefreshToken(); |
|
|
|
|
if (refreshToken == null || refreshToken === "") { |
|
|
|
|
@ -2389,6 +2379,28 @@ export class ApiService implements ApiServiceAbstraction {
@@ -2389,6 +2379,28 @@ export class ApiService implements ApiServiceAbstraction {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected async doApiTokenRefresh(): Promise<void> { |
|
|
|
|
const clientId = await this.tokenService.getClientId(); |
|
|
|
|
const clientSecret = await this.tokenService.getClientSecret(); |
|
|
|
|
|
|
|
|
|
const appId = await this.appIdService.getAppId(); |
|
|
|
|
const deviceRequest = new DeviceRequest(appId, this.platformUtilsService); |
|
|
|
|
|
|
|
|
|
const tokenRequest = new ApiTokenRequest( |
|
|
|
|
clientId, |
|
|
|
|
clientSecret, |
|
|
|
|
new TokenRequestTwoFactor(), |
|
|
|
|
deviceRequest |
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
const response = await this.postIdentityToken(tokenRequest); |
|
|
|
|
if (!(response instanceof IdentityTokenResponse)) { |
|
|
|
|
throw new Error("Invalid response received when refreshing api token"); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
await this.tokenService.setToken(response.accessToken); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private async send( |
|
|
|
|
method: "GET" | "POST" | "PUT" | "DELETE", |
|
|
|
|
path: string, |
|
|
|
|
|