-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
fefc43c
commit afa839f
Showing
6 changed files
with
232 additions
and
6 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,34 @@ | ||
import okta from "../../okta.app.mjs"; | ||
|
||
export default { | ||
key: "okta-create-user", | ||
name: "Create User", | ||
description: "Creates a new user in the Okta system. The user will receive an email with the account creation prompt.", | ||
version: "0.0.{{ts}}", | ||
type: "action", | ||
props: { | ||
okta, | ||
firstName: okta.propDefinitions.firstName, | ||
lastName: okta.propDefinitions.lastName, | ||
email: okta.propDefinitions.email, | ||
login: { | ||
...okta.propDefinitions.login, | ||
optional: true, | ||
}, | ||
mobilePhone: { | ||
...okta.propDefinitions.mobilePhone, | ||
optional: true, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.okta.createUser({ | ||
firstName: this.firstName, | ||
lastName: this.lastName, | ||
email: this.email, | ||
login: this.login, | ||
mobilePhone: this.mobilePhone, | ||
}); | ||
$.export("$summary", `Successfully created user ${this.firstName} ${this.lastName}`); | ||
return response; | ||
}, | ||
}; |
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,19 @@ | ||
import okta from "../../okta.app.mjs"; | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
key: "okta-get-user", | ||
name: "Get User", | ||
description: "Fetches the information of a specific user from the Okta system. [See the documentation](https://developer.okta.com/docs/reference/api/users/#get-user)", | ||
version: "0.0.{{ts}}", | ||
type: "action", | ||
props: { | ||
okta, | ||
userId: okta.propDefinitions.userId, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.okta.fetchUser(this.userId); | ||
$.export("$summary", `Successfully fetched user details for user ID ${this.userId}`); | ||
return response; | ||
}, | ||
}; |
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,20 @@ | ||
import okta from "../../okta.app.mjs"; | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
key: "okta-update-user", | ||
name: "Update User", | ||
description: "Updates the profile and/or credentials of a specific user in the Okta system. The mandatory props are 'user ID' and the details that need to be updated.", | ||
version: "0.0.${ts}", | ||
type: "action", | ||
props: { | ||
okta, | ||
userId: okta.propDefinitions.userId, | ||
updateDetails: okta.propDefinitions.updateDetails, | ||
}, | ||
async run({ $ }) { | ||
const response = await this.okta.updateUser(this.userId, this.updateDetails); | ||
$.export("$summary", `Successfully updated user with ID ${this.userId}`); | ||
return response; | ||
}, | ||
}; |
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 |
---|---|---|
@@ -1,11 +1,102 @@ | ||
import { axios } from "@pipedream/platform"; | ||
|
||
export default { | ||
type: "app", | ||
app: "okta", | ||
propDefinitions: {}, | ||
propDefinitions: { | ||
userId: { | ||
type: "string", | ||
label: "User ID", | ||
description: "The unique identifier of the user.", | ||
}, | ||
firstName: { | ||
type: "string", | ||
label: "First Name", | ||
description: "The first name of the user.", | ||
}, | ||
lastName: { | ||
type: "string", | ||
label: "Last Name", | ||
description: "The last name of the user.", | ||
}, | ||
email: { | ||
type: "string", | ||
label: "Email", | ||
description: "The email address of the user.", | ||
}, | ||
login: { | ||
type: "string", | ||
label: "Login", | ||
description: "The login for the user (optional).", | ||
optional: true, | ||
}, | ||
mobilePhone: { | ||
type: "string", | ||
label: "Mobile Phone", | ||
description: "The mobile phone number of the user (optional).", | ||
optional: true, | ||
}, | ||
updateDetails: { | ||
type: "object", | ||
label: "Update Details", | ||
description: "The details to update for the user.", | ||
}, | ||
}, | ||
methods: { | ||
// this.$auth contains connected account data | ||
authKeys() { | ||
console.log(Object.keys(this.$auth)); | ||
_baseUrl() { | ||
return "https://your-domain.okta.com/api/v1"; | ||
}, | ||
async _makeRequest(opts = {}) { | ||
const { | ||
$ = this, method = "GET", path, headers, ...otherOpts | ||
} = opts; | ||
return axios($, { | ||
...otherOpts, | ||
method, | ||
url: this._baseUrl() + path, | ||
headers: { | ||
...headers, | ||
"Authorization": `SSWS ${this.$auth.api_token}`, | ||
"Content-Type": "application/json", | ||
"Accept": "application/json", | ||
}, | ||
}); | ||
}, | ||
async createUser({ | ||
firstName, lastName, email, login, mobilePhone, | ||
}) { | ||
const user = { | ||
profile: { | ||
firstName, | ||
lastName, | ||
email, | ||
login: login || email, | ||
mobilePhone, | ||
}, | ||
credentials: { | ||
password: { | ||
value: "TempP@ssw0rd!", | ||
}, | ||
}, | ||
}; | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: "/users?activate=true", | ||
data: user, | ||
}); | ||
}, | ||
async fetchUser(userId) { | ||
return this._makeRequest({ | ||
method: "GET", | ||
path: `/users/${userId}`, | ||
}); | ||
}, | ||
async updateUser(userId, updateDetails) { | ||
return this._makeRequest({ | ||
method: "POST", | ||
path: `/users/${userId}`, | ||
data: updateDetails, | ||
}); | ||
}, | ||
}, | ||
}; | ||
}; |
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 |
---|---|---|
|
@@ -12,4 +12,4 @@ | |
"publishConfig": { | ||
"access": "public" | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
components/okta/sources/watch-new-events/watch-new-events.mjs
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,62 @@ | ||
import { axios } from "@pipedream/platform"; | ||
import okta from "../../okta.app.mjs"; | ||
|
||
export default { | ||
key: "okta-watch-new-events", | ||
name: "Watch New Events", | ||
description: "Emit new event when the system observes a new event. [See the documentation](https://developer.okta.com/docs/api/)", | ||
version: "0.0.1", | ||
type: "source", | ||
dedupe: "unique", | ||
props: { | ||
okta, | ||
db: "$.service.db", | ||
timer: { | ||
type: "$.interface.timer", | ||
default: { | ||
intervalSeconds: 300, // every 5 minutes | ||
}, | ||
}, | ||
}, | ||
hooks: { | ||
async deploy() { | ||
// Fetch the last 50 events to avoid duplicates on initial run | ||
const since = new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString(); // 1 day ago | ||
const events = await this.okta._makeRequest({ | ||
path: `/logs?since=${since}&limit=50`, | ||
}); | ||
events.forEach((event) => { | ||
this.$emit(event, { | ||
id: event.uuid, | ||
summary: `New event: ${event.eventType}`, | ||
ts: Date.parse(event.published), | ||
}); | ||
}); | ||
// Update the last event time to the most recent event's published time | ||
if (events.length > 0) { | ||
const latestEventTime = events[0].published; | ||
this.db.set("lastEventTime", latestEventTime); | ||
} | ||
}, | ||
}, | ||
async run() { | ||
const lastEventTime = this.db.get("lastEventTime") || new Date().toISOString(); | ||
const events = await this.okta._makeRequest({ | ||
path: `/logs?since=${lastEventTime}&limit=100`, | ||
}); | ||
|
||
events.forEach((event) => { | ||
this.$emit(event, { | ||
id: event.uuid, | ||
summary: `New event: ${event.eventType}`, | ||
ts: Date.parse(event.published), | ||
}); | ||
}); | ||
|
||
// Update the last event time to the most recent event's published time | ||
if (events.length > 0) { | ||
const mostRecentEvent = events[0].published; | ||
this.db.set("lastEventTime", mostRecentEvent); | ||
} | ||
}, | ||
}; |