-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d719899
commit 43971c2
Showing
7 changed files
with
754 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}, | ||
}; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.