Skip to content

Commit 8f097ec

Browse files
feat: add organization parameter support to resetPassword API (#1286)
1 parent 81ad6cf commit 8f097ec

File tree

3 files changed

+75
-1
lines changed

3 files changed

+75
-1
lines changed

src/core/services/AuthenticationOrchestrator.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,19 @@ export class AuthenticationOrchestrator implements IAuthenticationProvider {
358358

359359
async resetPassword(parameters: ResetPasswordParameters): Promise<void> {
360360
const { headers, ...payload } = parameters;
361-
const body = {
361+
const body: {
362+
client_id: string;
363+
email: string;
364+
connection: string;
365+
organization?: string;
366+
} = {
362367
client_id: this.clientId,
363368
email: payload.email,
364369
connection: payload.connection,
365370
};
371+
if (payload.organization) {
372+
body.organization = payload.organization;
373+
}
366374
const { json, response } = await this.client.post<void>(
367375
'/dbconnections/change_password',
368376
body,

src/core/services/__tests__/AuthenticationOrchestrator.spec.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,71 @@ describe('AuthenticationOrchestrator', () => {
447447
);
448448
});
449449

450+
it('resetPassword should include organization when provided', async () => {
451+
mockHttpClientInstance.post.mockResolvedValueOnce({
452+
json: {},
453+
response: new Response(null, { status: 200 }),
454+
});
455+
await orchestrator.resetPassword({
456+
457+
connection: 'Username-Password-Authentication',
458+
organization: 'org_123',
459+
});
460+
461+
expect(mockHttpClientInstance.post).toHaveBeenCalledWith(
462+
'/dbconnections/change_password',
463+
{
464+
client_id: clientId,
465+
466+
connection: 'Username-Password-Authentication',
467+
organization: 'org_123',
468+
},
469+
undefined
470+
);
471+
});
472+
473+
it('resetPassword should handle custom headers', async () => {
474+
mockHttpClientInstance.post.mockResolvedValueOnce({
475+
json: {},
476+
response: new Response(null, { status: 200 }),
477+
});
478+
await orchestrator.resetPassword({
479+
480+
connection: 'Username-Password-Authentication',
481+
organization: 'org_456',
482+
headers: { 'X-Custom-Header': 'custom-value' },
483+
});
484+
485+
expect(mockHttpClientInstance.post).toHaveBeenCalledWith(
486+
'/dbconnections/change_password',
487+
{
488+
client_id: clientId,
489+
490+
connection: 'Username-Password-Authentication',
491+
organization: 'org_456',
492+
},
493+
{ 'X-Custom-Header': 'custom-value' }
494+
);
495+
});
496+
497+
it('resetPassword should handle error response', async () => {
498+
const errorResponse = {
499+
error: 'invalid_request',
500+
error_description: 'Invalid connection',
501+
};
502+
mockHttpClientInstance.post.mockResolvedValueOnce({
503+
json: errorResponse,
504+
response: new Response(null, { status: 400 }),
505+
});
506+
507+
await expect(
508+
orchestrator.resetPassword({
509+
510+
connection: 'Invalid-Connection',
511+
})
512+
).rejects.toThrow(AuthError);
513+
});
514+
450515
it('createUser should send correct payload and return camelCased response', async () => {
451516
const userResponse = {
452517
id: 'user_id_123',

src/types/parameters.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ export interface UserInfoParameters extends RequestOptions {
214214
export interface ResetPasswordParameters extends RequestOptions {
215215
email: string;
216216
connection: string;
217+
organization?: string;
217218
}
218219

219220
/** Parameters for creating a new user in a database connection. */

0 commit comments

Comments
 (0)