9 changed files with 158 additions and 97 deletions
@ -1 +1 @@
@@ -1 +1 @@
|
||||
Subproject commit e0cc754d6fe962a5e7eae6d1dead8b44606d4853 |
||||
Subproject commit 6b8508579f89b4c54afa6aab2b7155aac70fb8a9 |
||||
@ -0,0 +1,65 @@
@@ -0,0 +1,65 @@
|
||||
import { LogInStrategy } from "jslib-common/misc/logInStrategies/logIn.strategy"; |
||||
|
||||
import { ApiTokenRequest } from "jslib-common/models/request/identityToken/apiTokenRequest"; |
||||
|
||||
import { IdentityTokenResponse } from "jslib-common/models/response/identityTokenResponse"; |
||||
|
||||
import { AccountKeys, AccountProfile, AccountTokens } from "jslib-common/models/domain/account"; |
||||
import { AuthResult } from "jslib-common/models/domain/authResult"; |
||||
import { ApiLogInCredentials } from "jslib-common/models/domain/logInCredentials"; |
||||
|
||||
import { Account, DirectoryConfigurations, DirectorySettings } from "src/models/account"; |
||||
|
||||
export class OrganizationLogInStrategy extends LogInStrategy { |
||||
tokenRequest: ApiTokenRequest; |
||||
|
||||
async logIn(credentials: ApiLogInCredentials) { |
||||
this.tokenRequest = new ApiTokenRequest( |
||||
credentials.clientId, |
||||
credentials.clientSecret, |
||||
await this.buildTwoFactor(), |
||||
await this.buildDeviceRequest() |
||||
); |
||||
|
||||
return this.startLogIn(); |
||||
} |
||||
|
||||
protected async processTokenResponse(response: IdentityTokenResponse): Promise<AuthResult> { |
||||
await this.saveAccountInformation(response); |
||||
return new AuthResult(); |
||||
} |
||||
|
||||
protected async saveAccountInformation(tokenResponse: IdentityTokenResponse) { |
||||
const clientId = this.tokenRequest.clientId; |
||||
const entityId = clientId.split("organization.")[1]; |
||||
const clientSecret = this.tokenRequest.clientSecret; |
||||
|
||||
await this.stateService.addAccount( |
||||
new Account({ |
||||
profile: { |
||||
...new AccountProfile(), |
||||
...{ |
||||
userId: entityId, |
||||
apiKeyClientId: clientId, |
||||
entityId: entityId, |
||||
}, |
||||
}, |
||||
tokens: { |
||||
...new AccountTokens(), |
||||
...{ |
||||
accessToken: tokenResponse.accessToken, |
||||
refreshToken: tokenResponse.refreshToken, |
||||
}, |
||||
}, |
||||
keys: { |
||||
...new AccountKeys(), |
||||
...{ |
||||
apiKeyClientSecret: clientSecret, |
||||
}, |
||||
}, |
||||
directorySettings: new DirectorySettings(), |
||||
directoryConfigurations: new DirectoryConfigurations(), |
||||
}) |
||||
); |
||||
} |
||||
} |
||||
@ -0,0 +1,42 @@
@@ -0,0 +1,42 @@
|
||||
import { |
||||
TwoFactorProviderDetails, |
||||
TwoFactorService, |
||||
} from "jslib-common/abstractions/twoFactor.service"; |
||||
|
||||
import { TwoFactorProviderType } from "jslib-common/enums/twoFactorProviderType"; |
||||
|
||||
import { IdentityTwoFactorResponse } from "jslib-common/models/response/identityTwoFactorResponse"; |
||||
|
||||
export class NoopTwoFactorService implements TwoFactorService { |
||||
init() { |
||||
// Noop
|
||||
} |
||||
|
||||
getSupportedProviders(win: Window): TwoFactorProviderDetails[] { |
||||
return null; |
||||
} |
||||
|
||||
getDefaultProvider(webAuthnSupported: boolean): TwoFactorProviderType { |
||||
return null; |
||||
} |
||||
|
||||
setSelectedProvider(type: TwoFactorProviderType) { |
||||
// Noop
|
||||
} |
||||
|
||||
clearSelectedProvider() { |
||||
// Noop
|
||||
} |
||||
|
||||
setProviders(response: IdentityTwoFactorResponse) { |
||||
// Noop
|
||||
} |
||||
|
||||
clearProviders() { |
||||
// Noop
|
||||
} |
||||
|
||||
getProviders(): Map<TwoFactorProviderType, { [key: string]: string }> { |
||||
return null; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue