Skip to content

Commit cabe1bf

Browse files
antsgarkmantel
authored andcommitted
chore: Add serverPassword param to endpoints (standardnotes#2919) [skip e2e]
* chore: send server password param to delete account endpoint * chore: send server password param to disable mfa endpoint * chore: modify tests * chore: force challenge prompt for mfa disable * chore: fix eslint errors * chore: add server passsword to get recovery codes * chore: fix tests * chore: pass server password as header
1 parent fa8a7f0 commit cabe1bf

29 files changed

+298
-62
lines changed

packages/api/src/Domain/Client/Auth/AuthApiService.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,19 @@ export class AuthApiService implements AuthApiServiceInterface {
2222
this.operationsInProgress = new Map()
2323
}
2424

25-
async generateRecoveryCodes(): Promise<HttpResponse<GenerateRecoveryCodesResponseBody>> {
25+
async generateRecoveryCodes(dto: {
26+
serverPassword: string
27+
}): Promise<HttpResponse<GenerateRecoveryCodesResponseBody>> {
2628
if (this.operationsInProgress.get(AuthApiOperations.GenerateRecoveryCodes)) {
2729
throw new ApiCallError(ErrorMessage.GenericInProgress)
2830
}
2931

3032
this.operationsInProgress.set(AuthApiOperations.GenerateRecoveryCodes, true)
3133

3234
try {
33-
const response = await this.authServer.generateRecoveryCodes()
35+
const response = await this.authServer.generateRecoveryCodes({
36+
headers: [{ key: 'x-server-password', value: dto.serverPassword }],
37+
})
3438

3539
return response
3640
} catch (error) {

packages/api/src/Domain/Client/Auth/AuthApiServiceInterface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import {
66
} from '../../Response'
77

88
export interface AuthApiServiceInterface {
9-
generateRecoveryCodes(): Promise<HttpResponse<GenerateRecoveryCodesResponseBody>>
9+
generateRecoveryCodes(dto: { serverPassword: string }): Promise<HttpResponse<GenerateRecoveryCodesResponseBody>>
1010
recoveryKeyParams(dto: {
1111
username: string
1212
codeChallenge: string

packages/api/src/Domain/Client/User/UserApiService.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,19 @@ export class UserApiService implements UserApiServiceInterface {
2727
this.operationsInProgress = new Map()
2828
}
2929

30-
async deleteAccount(userUuid: string): Promise<HttpResponse<UserDeletionResponseBody>> {
30+
async deleteAccount(dto: {
31+
userUuid: string
32+
serverPassword: string
33+
}): Promise<HttpResponse<UserDeletionResponseBody>> {
3134
this.lockOperation(UserApiOperations.DeletingAccount)
3235

3336
try {
34-
const response = await this.userServer.deleteAccount({
35-
userUuid: userUuid,
36-
})
37+
const response = await this.userServer.deleteAccount(
38+
{
39+
userUuid: dto.userUuid,
40+
},
41+
{ headers: [{ key: 'x-server-password', value: dto.serverPassword }] },
42+
)
3743

3844
this.unlockOperation(UserApiOperations.DeletingAccount)
3945

packages/api/src/Domain/Client/User/UserApiServiceInterface.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ export interface UserApiServiceInterface {
2222
requestType: UserRequestType
2323
}): Promise<HttpResponse<UserRequestResponseBody>>
2424

25-
deleteAccount(userUuid: string): Promise<HttpResponse<UserDeletionResponseBody>>
25+
deleteAccount(dto: {
26+
userUuid: string
27+
serverPassword: string | undefined
28+
}): Promise<HttpResponse<UserDeletionResponseBody>>
2629
}

packages/api/src/Domain/Http/HttpService.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ export class HttpService implements HttpServiceInterface {
9191
params,
9292
verb: HttpVerb.Get,
9393
authentication: options?.authentication ?? this.getSessionAccessToken(),
94+
customHeaders: options?.headers,
9495
})
9596
}
9697

@@ -123,6 +124,7 @@ export class HttpService implements HttpServiceInterface {
123124
params,
124125
verb: HttpVerb.Put,
125126
authentication: options?.authentication ?? this.getSessionAccessToken(),
127+
customHeaders: options?.headers,
126128
})
127129
}
128130

@@ -141,6 +143,7 @@ export class HttpService implements HttpServiceInterface {
141143
params,
142144
verb: HttpVerb.Delete,
143145
authentication: options?.authentication ?? this.getSessionAccessToken(),
146+
customHeaders: options?.headers,
144147
})
145148
}
146149

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface GenerateRecoveryCodesRequestParams {
2+
serverPassword: string
3+
}

packages/api/src/Domain/Request/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ export * from './Authenticator/DeleteAuthenticatorRequestParams'
22
export * from './Authenticator/GenerateAuthenticatorAuthenticationOptionsRequestParams'
33
export * from './Authenticator/ListAuthenticatorsRequestParams'
44
export * from './Authenticator/VerifyAuthenticatorRegistrationResponseRequestParams'
5+
export * from './Recovery/GenerateRecoveryCodesRequestParams'
56
export * from './Recovery/RecoveryKeyParamsRequestParams'
67
export * from './Recovery/SignInWithRecoveryCodesRequestParams'
78
export * from './Revision/DeleteRevisionRequestParams'

packages/api/src/Domain/Server/Auth/AuthServer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ import {
88
} from '../../Response'
99
import { AuthServerInterface } from './AuthServerInterface'
1010
import { Paths } from './Paths'
11+
import { HttpRequestOptions } from '../../Http/HttpRequestOptions'
1112

1213
export class AuthServer implements AuthServerInterface {
1314
constructor(private httpService: HttpServiceInterface) {}
1415

15-
async generateRecoveryCodes(): Promise<HttpResponse<GenerateRecoveryCodesResponseBody>> {
16-
return this.httpService.post(Paths.v1.generateRecoveryCodes)
16+
async generateRecoveryCodes(options?: HttpRequestOptions): Promise<HttpResponse<GenerateRecoveryCodesResponseBody>> {
17+
return this.httpService.post(Paths.v1.generateRecoveryCodes, undefined, options)
1718
}
1819

1920
async recoveryKeyParams(

packages/api/src/Domain/Server/Auth/AuthServerInterface.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import {
55
RecoveryKeyParamsResponseBody,
66
SignInWithRecoveryCodesResponseBody,
77
} from '../../Response'
8+
import { HttpRequestOptions } from '../../Http/HttpRequestOptions'
89

910
export interface AuthServerInterface {
10-
generateRecoveryCodes(): Promise<HttpResponse<GenerateRecoveryCodesResponseBody>>
11+
generateRecoveryCodes(options?: HttpRequestOptions): Promise<HttpResponse<GenerateRecoveryCodesResponseBody>>
1112
recoveryKeyParams(params: RecoveryKeyParamsRequestParams): Promise<HttpResponse<RecoveryKeyParamsResponseBody>>
1213
signInWithRecoveryCodes(
1314
params: SignInWithRecoveryCodesRequestParams,

packages/api/src/Domain/Server/User/UserServer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,16 @@ import { UserRegistrationResponseBody } from '../../Response/User/UserRegistrati
88
import { Paths } from './Paths'
99
import { UserServerInterface } from './UserServerInterface'
1010
import { UserUpdateRequestParams } from '../../Request/User/UserUpdateRequestParams'
11+
import { HttpRequestOptions } from '../../Http/HttpRequestOptions'
1112

1213
export class UserServer implements UserServerInterface {
1314
constructor(private httpService: HttpServiceInterface) {}
1415

15-
async deleteAccount(params: UserDeletionRequestParams): Promise<HttpResponse<UserDeletionResponseBody>> {
16-
return this.httpService.delete(Paths.v1.deleteAccount(params.userUuid), params)
16+
async deleteAccount(
17+
params: UserDeletionRequestParams,
18+
options?: HttpRequestOptions,
19+
): Promise<HttpResponse<UserDeletionResponseBody>> {
20+
return this.httpService.delete(Paths.v1.deleteAccount(params.userUuid), params, options)
1721
}
1822

1923
async register(params: UserRegistrationRequestParams): Promise<HttpResponse<UserRegistrationResponseBody>> {

0 commit comments

Comments
 (0)