Skip to content
Open
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
25 changes: 25 additions & 0 deletions src/authorization-client/authorization-client.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ test('AuthorizationClient.getGroupMembers should get group members', async (t) =
test('AuthorizationClient.getConnections should get connections', async (t) => {
const { authorizationClient, counter } = setupTest();
const connections = await authorizationClient.getConnections();
console.log(connections)
t.truthy(connections);
});

Expand All @@ -53,6 +54,30 @@ test('AuthorizationClient.getGroups should get groups', async (t) => {
t.truthy(response.groups);
});

test('AuthorizationClient.enableConnection should enable application for specified connection', async (t) => {
const testConnectionId = 'con_RuQniJyhsNJhzggX';
const defaultAppId = 'ZEBLdpFpHXg55cejEFEKphF03fo9-zJ8'
const { authorizationClient, counter } = setupTest();
const response = await authorizationClient.enableConnection(
{
connectionId: testConnectionId,
applicationId: defaultAppId
}
);
t.truthy(response.enabled_clients.length);
});

test('AuthorizationClient.disableConnection should disable all applications for specified connection', async (t) => {
const testConnectionId = 'con_RuQniJyhsNJhzggX';
const { authorizationClient, counter } = setupTest();
const response = await authorizationClient.disableConnection(
{
connectionId: testConnectionId
}
);
t.truthy(!response.enabled_clients.length);
});

// Returns a new instance of AuthorizationClient and a counter counting the number of times getAccessToken is called.
function setupTest() {
const dummyAccessToken = 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlJFWXlNVEV3UWtFNVJrVTVNVVU1TXpaQ1JFRkdNMEl3UTBNM05EY3hNRFExUXpZd01USTJNZyJ9.eyJpc3MiOiJ4eHgiLCJzdWIiOiJ4eHgiLCJhdWQiOiJ4eHgiLCJpYXQiOjE1NTg1MDQ2NjMsImV4cCI6MTU1ODUwNDY2Mywibm9uY2UiOiJYWFgifQ.iPNiKdnMfuSz6GD83FfKqB2dMmvlrFtCjDiQ7pgN0Qpyk1XyO0z72ZMG88yH1OGZCGswdw-f8KRjOZ5lSLeiXfePjOYGkPT9izBjYJtzzOBAQ4mx936BwFK8NB204AhhqpTsC7JYsw4vm7r1EjUcN1fMmCSAqxOrPNmq0R9lOiN_aSkQdJlCcqTkUlEorufqjRr_uUbNKHHcx93PhFKezTAbiIOA910yUFbCiDLIYwTkmdbkFZSyeDA12Pl9ZFW9v61k3azmH9AhyDc6QKPLb92CX7k7ZKnJw0GQ5wf5j2wfxtYjRGz7CPNwNXPVUJu67w7HuBCDT8unI-rO7W2okA';
Expand Down
10 changes: 10 additions & 0 deletions src/authorization-client/authorization-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import { removeUserFromRoles, Input as IRemoveUserFromRolesInput } from '../user
import { calculateRoles, Input as ICalculateRolesInput } from '../users/calculate-roles';
// Connections
import { getConnections } from '../connections/get-connections';
import { disableConnection, Input as IDisableConnectionInput } from '../connections/disable-connection';
import { enableConnection, Input as IEnableConnectionInput } from '../connections/enable-connection';

export class AuthorizationClient {
private _options: IAuthorizationClientOptions;
Expand Down Expand Up @@ -207,6 +209,14 @@ export class AuthorizationClient {
return getConnections(this._options.extensionUrl, await this._getAccessToken())();
}

public async disableConnection(input: IDisableConnectionInput) {
return disableConnection(this._options.extensionUrl, await this._getAccessToken())(input);
}

public async enableConnection(input: IEnableConnectionInput) {
return enableConnection(this._options.extensionUrl, await this._getAccessToken())(input);
}

// Return cached access token unless it does not exist or is expired.
// If there is a pending request to get access token, wait for that
// request to finish before continuing.
Expand Down
18 changes: 18 additions & 0 deletions src/connections/disable-connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IAuth0AuthorizationApiConnection } from '../interfaces';
import { patch } from '../common/request';

export interface Input {
connectionId: string;
}

export function disableConnection(extensionUrl: string, accessToken: string) {
return (input: Input): Promise<IAuth0AuthorizationApiConnection> => {
return patch({
accessToken,
url: `${extensionUrl}/connections/${input.connectionId}`,
body: {
"enabled_clients": []
}
});
}
}
20 changes: 20 additions & 0 deletions src/connections/enable-connection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { IAuth0AuthorizationApiConnection } from '../interfaces';
import { patch } from '../common/request';

export interface Input {
connectionId: string;
applicationId: string;
}

export function enableConnection(extensionUrl: string, accessToken: string) {
return (input: Input): Promise<IAuth0AuthorizationApiConnection> => {
console.log("!!!" + `${extensionUrl}/connections/${input.connectionId}`)
return patch({
accessToken,
url: `${extensionUrl}/connections/${input.connectionId}`,
body: {
"enabled_clients": [`"${input.applicationId}"`]
}
});
}
}
1 change: 1 addition & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ export interface IAuth0AuthorizationApiConnection {
name: string;
display_name: string;
id: string;
enabled_clients: string[];
}