Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/core/services/AuthenticationOrchestrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,11 +358,19 @@ export class AuthenticationOrchestrator implements IAuthenticationProvider {

async resetPassword(parameters: ResetPasswordParameters): Promise<void> {
const { headers, ...payload } = parameters;
const body = {
const body: {
client_id: string;
email: string;
connection: string;
organization?: string;
} = {
client_id: this.clientId,
email: payload.email,
connection: payload.connection,
};
if (payload.organization) {
body.organization = payload.organization;
}
const { json, response } = await this.client.post<void>(
'/dbconnections/change_password',
body,
Expand Down
65 changes: 65 additions & 0 deletions src/core/services/__tests__/AuthenticationOrchestrator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,71 @@ describe('AuthenticationOrchestrator', () => {
);
});

it('resetPassword should include organization when provided', async () => {
mockHttpClientInstance.post.mockResolvedValueOnce({
json: {},
response: new Response(null, { status: 200 }),
});
await orchestrator.resetPassword({
email: 'info@auth0.com',
connection: 'Username-Password-Authentication',
organization: 'org_123',
});

expect(mockHttpClientInstance.post).toHaveBeenCalledWith(
'/dbconnections/change_password',
{
client_id: clientId,
email: 'info@auth0.com',
connection: 'Username-Password-Authentication',
organization: 'org_123',
},
undefined
);
});

it('resetPassword should handle custom headers', async () => {
mockHttpClientInstance.post.mockResolvedValueOnce({
json: {},
response: new Response(null, { status: 200 }),
});
await orchestrator.resetPassword({
email: 'info@auth0.com',
connection: 'Username-Password-Authentication',
organization: 'org_456',
headers: { 'X-Custom-Header': 'custom-value' },
});

expect(mockHttpClientInstance.post).toHaveBeenCalledWith(
'/dbconnections/change_password',
{
client_id: clientId,
email: 'info@auth0.com',
connection: 'Username-Password-Authentication',
organization: 'org_456',
},
{ 'X-Custom-Header': 'custom-value' }
);
});

it('resetPassword should handle error response', async () => {
const errorResponse = {
error: 'invalid_request',
error_description: 'Invalid connection',
};
mockHttpClientInstance.post.mockResolvedValueOnce({
json: errorResponse,
response: new Response(null, { status: 400 }),
});

await expect(
orchestrator.resetPassword({
email: 'info@auth0.com',
connection: 'Invalid-Connection',
})
).rejects.toThrow(AuthError);
});

it('createUser should send correct payload and return camelCased response', async () => {
const userResponse = {
id: 'user_id_123',
Expand Down
1 change: 1 addition & 0 deletions src/types/parameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ export interface UserInfoParameters extends RequestOptions {
export interface ResetPasswordParameters extends RequestOptions {
email: string;
connection: string;
organization?: string;
}

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