Skip to content

Commit c8d50b5

Browse files
committed
Feat: Added Support for Connected Accounts
1 parent 51302b5 commit c8d50b5

3 files changed

Lines changed: 225 additions & 0 deletions

File tree

src/management/__generated/managers/users-manager.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type {
1616
GetUserOrganizations200Response,
1717
GetUsers200Response,
1818
GetUsers200ResponseOneOfInner,
19+
ListUserConnectedAccountsResponseContent,
1920
PatchAuthenticationMethodsByAuthenticationMethodIdRequest,
2021
PostAuthenticationMethods201Response,
2122
PostAuthenticationMethodsRequest,
@@ -52,6 +53,7 @@ import type {
5253
DeleteUsersByIdRequest,
5354
GetAuthenticationMethodsRequest,
5455
GetAuthenticationMethodsByAuthenticationMethodIdRequest,
56+
GetConnectedAccountsRequest,
5557
GetEnrollmentsRequest,
5658
GetFederatedConnectionsTokensetsRequest,
5759
GetLogsByUserRequest,
@@ -447,6 +449,44 @@ export class UsersManager extends BaseAPI {
447449
return runtime.JSONApiResponse.fromResponse(response);
448450
}
449451

452+
/**
453+
* Retrieve all connected accounts associated with the user.
454+
* Get a User's Connected Accounts
455+
*
456+
* @throws {RequiredError}
457+
*/
458+
async getConnectedAccounts(
459+
requestParameters: GetConnectedAccountsRequest,
460+
initOverrides?: InitOverride
461+
): Promise<ApiResponse<ListUserConnectedAccountsResponseContent>> {
462+
runtime.validateRequiredRequestParams(requestParameters, ['id']);
463+
464+
const queryParameters = runtime.applyQueryParams(requestParameters, [
465+
{
466+
key: 'from',
467+
config: {},
468+
},
469+
{
470+
key: 'take',
471+
config: {},
472+
},
473+
]);
474+
475+
const response = await this.request(
476+
{
477+
path: `/users/{id}/connected-accounts`.replace(
478+
'{id}',
479+
encodeURIComponent(String(requestParameters.id))
480+
),
481+
method: 'GET',
482+
query: queryParameters,
483+
},
484+
initOverrides
485+
);
486+
487+
return runtime.JSONApiResponse.fromResponse(response);
488+
}
489+
450490
/**
451491
* Retrieve the first confirmed <a href="https://auth0.com/docs/multifactor-authentication/guardian">Guardian</a> enrollment for a user.
452492
* Get the First Confirmed Multi-factor Authentication Enrollment

src/management/__generated/models/index.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3217,6 +3217,59 @@ export interface ClientUpdateSignedRequestObject {
32173217
*/
32183218
credentials?: Array<ClientClientAuthenticationMethodsPrivateKeyJwtCredentialsInner>;
32193219
}
3220+
/**
3221+
*
3222+
*/
3223+
export interface ConnectedAccount {
3224+
/**
3225+
* The unique identifier for the connected account.
3226+
*
3227+
*/
3228+
id: string;
3229+
/**
3230+
* The name of the connection associated with the account.
3231+
*
3232+
*/
3233+
connection: string;
3234+
/**
3235+
* The unique identifier of the connection associated with the account.
3236+
*
3237+
*/
3238+
connection_id: string;
3239+
/**
3240+
* The authentication strategy used by the connection.
3241+
*
3242+
*/
3243+
strategy: string;
3244+
/**
3245+
*/
3246+
access_type: ConnectedAccountAccessTypeEnum;
3247+
/**
3248+
* The scopes granted for this connected account.
3249+
*
3250+
*/
3251+
scopes?: Array<string>;
3252+
/**
3253+
* ISO 8601 timestamp when the connected account was created.
3254+
*
3255+
*/
3256+
created_at: string;
3257+
/**
3258+
* ISO 8601 timestamp when the connected account expires.
3259+
*
3260+
*/
3261+
expires_at?: string;
3262+
}
3263+
3264+
/**
3265+
* The access type for the connected account.
3266+
*/
3267+
export const ConnectedAccountAccessTypeEnum = {
3268+
offline: 'offline',
3269+
} as const;
3270+
export type ConnectedAccountAccessTypeEnum =
3271+
(typeof ConnectedAccountAccessTypeEnum)[keyof typeof ConnectedAccountAccessTypeEnum];
3272+
32203273
/**
32213274
*
32223275
*/
@@ -10016,6 +10069,19 @@ export interface ListUserAttributeProfilesPaginatedResponseContent {
1001610069
*/
1001710070
user_attribute_profiles?: Array<UserAttributeProfile>;
1001810071
}
10072+
/**
10073+
*
10074+
*/
10075+
export interface ListUserConnectedAccountsResponseContent {
10076+
/**
10077+
*/
10078+
connected_accounts: Array<ConnectedAccount>;
10079+
/**
10080+
* The token to retrieve the next page of connected accounts (if there is one)
10081+
*
10082+
*/
10083+
next?: string;
10084+
}
1001910085
/**
1002010086
*
1002110087
*/
@@ -23736,6 +23802,26 @@ export interface GetAuthenticationMethodsByAuthenticationMethodIdRequest {
2373623802
*/
2373723803
authentication_method_id: string;
2373823804
}
23805+
/**
23806+
*
23807+
*/
23808+
export interface GetConnectedAccountsRequest {
23809+
/**
23810+
* ID of the user to list connected accounts for.
23811+
*
23812+
*/
23813+
id: string;
23814+
/**
23815+
* Optional Id from which to start selection.
23816+
*
23817+
*/
23818+
from?: string;
23819+
/**
23820+
* Number of results to return. Defaults to 10 with a maximum of 20
23821+
*
23822+
*/
23823+
take?: number;
23824+
}
2373923825
/**
2374023826
*
2374123827
*/

test/management/users.test.ts

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,4 +1727,103 @@ describe('UsersManager', () => {
17271727
expect(request.isDone()).toBe(true);
17281728
});
17291729
});
1730+
1731+
describe('#getConnectedAccounts', () => {
1732+
const data = {
1733+
id: 'user_id',
1734+
};
1735+
1736+
let scope: nock.Scope;
1737+
1738+
beforeEach(() => {
1739+
scope = nock(API_URL).get(`/users/${data.id}/connected-accounts`).reply(200, []);
1740+
});
1741+
1742+
it('should return a promise when no callback is given', (done) => {
1743+
expect(usersManager.getConnectedAccounts(data).then(() => done())).toBeInstanceOf(Promise);
1744+
});
1745+
1746+
it('should perform a GET request to /api/v2/users/user_id/connected-accounts', async () => {
1747+
await usersManager.getConnectedAccounts(data);
1748+
expect(scope.isDone()).toBe(true);
1749+
});
1750+
1751+
it('should pass any errors to the promise catch handler', async () => {
1752+
nock.cleanAll();
1753+
1754+
nock(API_URL).get(`/users/${data.id}/connected-accounts`).reply(500, {});
1755+
1756+
try {
1757+
await usersManager.getConnectedAccounts(data);
1758+
} catch (err) {
1759+
expect(err).toBeDefined();
1760+
}
1761+
});
1762+
1763+
it('should include the token in the authorization header', async () => {
1764+
nock.cleanAll();
1765+
1766+
const request = nock(API_URL)
1767+
.get(`/users/${data.id}/connected-accounts`)
1768+
.matchHeader('authorization', `Bearer ${token}`)
1769+
.reply(200, []);
1770+
1771+
await usersManager.getConnectedAccounts(data);
1772+
expect(request.isDone()).toBe(true);
1773+
});
1774+
1775+
it('should pass the body of the response to the "then" handler', async () => {
1776+
nock.cleanAll();
1777+
1778+
const connectedAccountsData = [
1779+
{
1780+
id: 'conn_123',
1781+
connection: 'google-oauth2',
1782+
connection_id: 'con_abc123',
1783+
strategy: 'google-oauth2',
1784+
access_type: 'offline',
1785+
scopes: ['profile', 'email'],
1786+
created_at: '2023-01-01T00:00:00.000Z',
1787+
expires_at: '2024-01-01T00:00:00.000Z',
1788+
},
1789+
];
1790+
1791+
const response = {
1792+
connected_accounts: connectedAccountsData,
1793+
next: null,
1794+
};
1795+
1796+
nock(API_URL).get(`/users/${data.id}/connected-accounts`).reply(200, response);
1797+
1798+
const connectedAccounts = await usersManager.getConnectedAccounts(data);
1799+
expect(connectedAccounts.data.connected_accounts).toBeInstanceOf(Array);
1800+
expect(connectedAccounts.data.connected_accounts.length).toBe(connectedAccountsData.length);
1801+
expect(connectedAccounts.data.connected_accounts[0].id).toBe(connectedAccountsData[0].id);
1802+
expect(connectedAccounts.data.connected_accounts[0].connection).toBe(connectedAccountsData[0].connection);
1803+
expect(connectedAccounts.data.connected_accounts[0].strategy).toBe(connectedAccountsData[0].strategy);
1804+
});
1805+
1806+
it('should pass the parameters in the query-string', async () => {
1807+
nock.cleanAll();
1808+
1809+
const params = {
1810+
from: 'conn_123',
1811+
take: 10,
1812+
};
1813+
const request = nock(API_URL)
1814+
.get(`/users/${data.id}/connected-accounts`)
1815+
.query(params)
1816+
.reply(200, []);
1817+
1818+
await usersManager.getConnectedAccounts({
1819+
id: data.id,
1820+
...params,
1821+
});
1822+
expect(request.isDone()).toBe(true);
1823+
});
1824+
1825+
it('should validate empty id', async () => {
1826+
await expect(usersManager.getConnectedAccounts({} as any)).rejects.toThrowError();
1827+
});
1828+
});
17301829
});

0 commit comments

Comments
 (0)