2022-02-01 00:51:32 +01:00
|
|
|
import { ApiService } from "../../abstractions/api.service";
|
|
|
|
import { AppIdService } from "../../abstractions/appId.service";
|
|
|
|
import { CryptoService } from "../../abstractions/crypto.service";
|
|
|
|
import { EnvironmentService } from "../../abstractions/environment.service";
|
|
|
|
import { LogService } from "../../abstractions/log.service";
|
|
|
|
import { MessagingService } from "../../abstractions/messaging.service";
|
|
|
|
import { PlatformUtilsService } from "../../abstractions/platformUtils.service";
|
|
|
|
import { StateService } from "../../abstractions/state.service";
|
2023-02-06 22:53:37 +01:00
|
|
|
import { TokenService } from "../../auth/abstractions/token.service";
|
|
|
|
import { TwoFactorService } from "../../auth/abstractions/two-factor.service";
|
|
|
|
import { KeyConnectorService } from "../abstractions/key-connector.service";
|
|
|
|
import { UserApiLogInCredentials } from "../models/domain/log-in-credentials";
|
|
|
|
import { UserApiTokenRequest } from "../models/request/identity-token/user-api-token.request";
|
|
|
|
import { IdentityTokenResponse } from "../models/response/identity-token.response";
|
2022-02-01 00:51:32 +01:00
|
|
|
|
2023-02-06 22:53:37 +01:00
|
|
|
import { LogInStrategy } from "./login.strategy";
|
2022-02-01 00:51:32 +01:00
|
|
|
|
2022-11-17 12:50:37 +01:00
|
|
|
export class UserApiLogInStrategy extends LogInStrategy {
|
|
|
|
tokenRequest: UserApiTokenRequest;
|
2022-02-01 00:51:32 +01:00
|
|
|
|
|
|
|
constructor(
|
|
|
|
cryptoService: CryptoService,
|
|
|
|
apiService: ApiService,
|
|
|
|
tokenService: TokenService,
|
|
|
|
appIdService: AppIdService,
|
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
messagingService: MessagingService,
|
|
|
|
logService: LogService,
|
|
|
|
stateService: StateService,
|
|
|
|
twoFactorService: TwoFactorService,
|
|
|
|
private environmentService: EnvironmentService,
|
|
|
|
private keyConnectorService: KeyConnectorService
|
|
|
|
) {
|
|
|
|
super(
|
|
|
|
cryptoService,
|
|
|
|
apiService,
|
|
|
|
tokenService,
|
|
|
|
appIdService,
|
|
|
|
platformUtilsService,
|
|
|
|
messagingService,
|
|
|
|
logService,
|
|
|
|
stateService,
|
|
|
|
twoFactorService
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2022-12-28 15:12:11 +01:00
|
|
|
async setUserKey(tokenResponse: IdentityTokenResponse) {
|
2022-02-01 00:51:32 +01:00
|
|
|
if (tokenResponse.apiUseKeyConnector) {
|
|
|
|
const keyConnectorUrl = this.environmentService.getKeyConnectorUrl();
|
|
|
|
await this.keyConnectorService.getAndSetKey(keyConnectorUrl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-17 12:50:37 +01:00
|
|
|
async logIn(credentials: UserApiLogInCredentials) {
|
|
|
|
this.tokenRequest = new UserApiTokenRequest(
|
2022-02-01 00:51:32 +01:00
|
|
|
credentials.clientId,
|
|
|
|
credentials.clientSecret,
|
|
|
|
await this.buildTwoFactor(),
|
|
|
|
await this.buildDeviceRequest()
|
|
|
|
);
|
|
|
|
|
|
|
|
return this.startLogIn();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected async saveAccountInformation(tokenResponse: IdentityTokenResponse) {
|
|
|
|
await super.saveAccountInformation(tokenResponse);
|
|
|
|
await this.stateService.setApiKeyClientId(this.tokenRequest.clientId);
|
|
|
|
await this.stateService.setApiKeyClientSecret(this.tokenRequest.clientSecret);
|
|
|
|
}
|
|
|
|
}
|