chore: auth verification (#2867) [skip e2e]
This commit is contained in:
@@ -13,8 +13,10 @@ export interface AuthClientInterface {
|
||||
password: string
|
||||
codeVerifier: string
|
||||
recoveryCodes: string
|
||||
hvmToken?: string
|
||||
}): Promise<
|
||||
| {
|
||||
success: true
|
||||
keyParams: AnyKeyParamsContent
|
||||
session: SessionBody
|
||||
user: {
|
||||
@@ -23,6 +25,9 @@ export interface AuthClientInterface {
|
||||
protocolVersion: string
|
||||
}
|
||||
}
|
||||
| false
|
||||
| {
|
||||
success: false
|
||||
captchaURL: string
|
||||
}
|
||||
>
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { AuthApiServiceInterface } from '@standardnotes/api'
|
||||
import { AnyKeyParamsContent } from '@standardnotes/common'
|
||||
import { isErrorResponse, SessionBody } from '@standardnotes/responses'
|
||||
import { isErrorResponse, getCaptchaHeader } from '@standardnotes/responses'
|
||||
|
||||
import { InternalEventBusInterface } from '../Internal/InternalEventBusInterface'
|
||||
import { AbstractService } from '../Service/AbstractService'
|
||||
@@ -45,37 +45,39 @@ export class AuthManager extends AbstractService implements AuthClientInterface
|
||||
}
|
||||
}
|
||||
|
||||
async signInWithRecoveryCodes(dto: {
|
||||
username: string
|
||||
password: string
|
||||
codeVerifier: string
|
||||
recoveryCodes: string
|
||||
}): Promise<
|
||||
| {
|
||||
keyParams: AnyKeyParamsContent
|
||||
session: SessionBody
|
||||
user: {
|
||||
uuid: string
|
||||
email: string
|
||||
protocolVersion: string
|
||||
}
|
||||
}
|
||||
| false
|
||||
> {
|
||||
async signInWithRecoveryCodes(
|
||||
dto: Parameters<AuthClientInterface['signInWithRecoveryCodes']>[0],
|
||||
): ReturnType<AuthClientInterface['signInWithRecoveryCodes']> {
|
||||
try {
|
||||
const result = await this.authApiService.signInWithRecoveryCodes(dto)
|
||||
|
||||
const captchaURL = getCaptchaHeader(result)
|
||||
|
||||
if (captchaURL) {
|
||||
return {
|
||||
success: false,
|
||||
captchaURL,
|
||||
}
|
||||
}
|
||||
|
||||
if (isErrorResponse(result)) {
|
||||
return false
|
||||
return {
|
||||
success: false,
|
||||
captchaURL: '',
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
keyParams: result.data.key_params as AnyKeyParamsContent,
|
||||
session: result.data.session,
|
||||
user: result.data.user,
|
||||
}
|
||||
} catch (error) {
|
||||
return false
|
||||
return {
|
||||
success: false,
|
||||
captchaURL: '',
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,13 +30,14 @@ export interface SessionsClientInterface {
|
||||
revokeAllOtherSessions(): Promise<void>
|
||||
|
||||
isCurrentSessionReadOnly(): boolean | undefined
|
||||
register(email: string, password: string, ephemeral: boolean): Promise<UserRegistrationResponseBody>
|
||||
register(email: string, password: string, hvmToken: string, ephemeral: boolean): Promise<UserRegistrationResponseBody>
|
||||
signIn(
|
||||
email: string,
|
||||
password: string,
|
||||
strict: boolean,
|
||||
ephemeral: boolean,
|
||||
minAllowedVersion?: ProtocolVersion,
|
||||
hvmToken?: string,
|
||||
): Promise<SessionManagerResponse>
|
||||
bypassChecksAndSignInWithRootKey(
|
||||
email: string,
|
||||
|
||||
@@ -142,6 +142,7 @@ export class UserService
|
||||
public async register(
|
||||
email: string,
|
||||
password: string,
|
||||
hvmToken: string,
|
||||
ephemeral = false,
|
||||
mergeLocal = true,
|
||||
): Promise<UserRegistrationResponseBody> {
|
||||
@@ -157,7 +158,7 @@ export class UserService
|
||||
|
||||
try {
|
||||
this.lockSyncing()
|
||||
const response = await this.sessions.register(email, password, ephemeral)
|
||||
const response = await this.sessions.register(email, password, hvmToken, ephemeral)
|
||||
|
||||
await this.notifyEventSync(AccountEvent.SignedInOrRegistered, {
|
||||
payload: {
|
||||
@@ -190,6 +191,7 @@ export class UserService
|
||||
ephemeral = false,
|
||||
mergeLocal = true,
|
||||
awaitSync = false,
|
||||
hvmToken?: string,
|
||||
): Promise<HttpResponse<SignInResponse>> {
|
||||
if (this.encryption.hasAccount()) {
|
||||
throw Error('Tried to sign in when an account already exists.')
|
||||
@@ -205,7 +207,7 @@ export class UserService
|
||||
/** Prevent a timed sync from occuring while signing in. */
|
||||
this.lockSyncing()
|
||||
|
||||
const { response } = await this.sessions.signIn(email, password, strict, ephemeral)
|
||||
const { response } = await this.sessions.signIn(email, password, strict, ephemeral, undefined, hvmToken)
|
||||
|
||||
if (!isErrorResponse(response)) {
|
||||
const notifyingFunction = awaitSync ? this.notifyEventSync.bind(this) : this.notifyEvent.bind(this)
|
||||
|
||||
@@ -21,6 +21,7 @@ export interface UserServiceInterface extends AbstractService<AccountEvent, Acco
|
||||
register(
|
||||
email: string,
|
||||
password: string,
|
||||
hvmToken: string,
|
||||
ephemeral: boolean,
|
||||
mergeLocal: boolean,
|
||||
): Promise<UserRegistrationResponseBody>
|
||||
@@ -31,6 +32,7 @@ export interface UserServiceInterface extends AbstractService<AccountEvent, Acco
|
||||
ephemeral: boolean,
|
||||
mergeLocal: boolean,
|
||||
awaitSync: boolean,
|
||||
hvmToken?: string,
|
||||
): Promise<HttpResponse<SignInResponse>>
|
||||
deleteAccount(): Promise<{
|
||||
error: boolean
|
||||
|
||||
@@ -203,7 +203,6 @@ export * from './User/SignedInOrRegisteredEventPayload'
|
||||
export * from './User/SignedOutEventPayload'
|
||||
export * from './User/UserService'
|
||||
export * from './User/UserServiceInterface'
|
||||
export * from './User/UserServiceInterface'
|
||||
export * from './UserEvent/NotificationService'
|
||||
export * from './UserEvent/NotificationServiceEvent'
|
||||
export * from './Vault/UseCase/AuthorizeVaultDeletion'
|
||||
|
||||
Reference in New Issue
Block a user