Skip to content

Commit

Permalink
Add Okta node
Browse files Browse the repository at this point in the history
  • Loading branch information
ShireenMissi committed Aug 2, 2024
1 parent d719899 commit 43971c2
Show file tree
Hide file tree
Showing 7 changed files with 754 additions and 0 deletions.
67 changes: 67 additions & 0 deletions packages/nodes-base/nodes/Okta/GenericFunctions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import type {
IDataObject,
IExecuteFunctions,
IExecuteSingleFunctions,
IHookFunctions,
IHttpRequestMethods,
IHttpRequestOptions,
ILoadOptionsFunctions,
INodeListSearchResult,
INodePropertyOptions,
} from 'n8n-workflow';

type OktaUser = {
profile: {
firstName: string;
lastName: string;
};
id: string;
};

export async function oktaApiRequest(
this: IExecuteFunctions | IExecuteSingleFunctions | IHookFunctions | ILoadOptionsFunctions,
method: IHttpRequestMethods,
resource: string,
body: IDataObject = {},
qs: IDataObject = {},
url?: string,
option: IDataObject = {},
): Promise<OktaUser[]> {
const credentials = await this.getCredentials('oktaApi');
const baseUrl = `${credentials.url as string}/api/v1/${resource}`;
const options: IHttpRequestOptions = {
headers: {
'Content-Type': 'application/json',
},
method,
body: Object.keys(body).length ? body : undefined,
qs: Object.keys(qs).length ? qs : undefined,
url: url ?? baseUrl,
json: true,
...option,
};
return await (this.helpers.httpRequestWithAuthentication.call(
this,
'oktaApi',
options,
) as Promise<OktaUser[]>);
}

export async function getUsers(
this: ILoadOptionsFunctions,
filter?: string,
): Promise<INodeListSearchResult> {
const responseData: OktaUser[] = await oktaApiRequest.call(this, 'GET', '/users/');
const filteredUsers = responseData.filter((user) => {
if (!filter) return true;
const fullName = `${user.profile.firstName} ${user.profile.lastName}`.toLowerCase();
return fullName.includes(filter.toLowerCase());
});
const users: INodePropertyOptions[] = filteredUsers.map((user) => ({
name: `${user.profile.firstName} ${user.profile.lastName}`,
value: user.id,
}));
return {
results: users,
};
}
3 changes: 3 additions & 0 deletions packages/nodes-base/nodes/Okta/Okta.dark.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions packages/nodes-base/nodes/Okta/Okta.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import type { INodeType, INodeTypeDescription } from 'n8n-workflow';
import { userFields, userOperations } from './UserDescription';
import { getUsers } from './GenericFunctions';

export class Okta implements INodeType {
description: INodeTypeDescription = {
displayName: 'Okta',
name: 'okta',
icon: { light: 'file:Okta.svg', dark: 'file:Okta.dark.svg' },
group: ['transform'],
version: 1,
subtitle: '={{$parameter["operation"] + ": " + $parameter["resource"]}}',
description: 'Use the Okta API',
defaults: {
name: 'Okta',
},
inputs: ['main'],
outputs: ['main'],
credentials: [
{
name: 'oktaApi',
required: true,
},
],
requestDefaults: {
returnFullResponse: true,
baseURL: '={{$credentials.url.replace(new RegExp("/$"), "")}}',
headers: {},
},
properties: [
{
displayName: 'Resource',
name: 'resource',
type: 'options',
noDataExpression: true,
options: [
{
name: 'User',
value: 'user',
},
],
default: 'user',
},

// USER
...userOperations,
...userFields,
],
};

methods = {
listSearch: {
getUsers,
},
};
}
3 changes: 3 additions & 0 deletions packages/nodes-base/nodes/Okta/Okta.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 43971c2

Please sign in to comment.