Skip to content

Commit

Permalink
okta init
Browse files Browse the repository at this point in the history
  • Loading branch information
luancazarine committed Jun 14, 2024
1 parent fefc43c commit afa839f
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 6 deletions.
34 changes: 34 additions & 0 deletions components/okta/actions/create-user/create-user.mjs
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;
},
};
19 changes: 19 additions & 0 deletions components/okta/actions/get-user/get-user.mjs
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";

Check failure on line 2 in components/okta/actions/get-user/get-user.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used

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;
},
};
20 changes: 20 additions & 0 deletions components/okta/actions/update-user/update-user.mjs
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";

Check failure on line 2 in components/okta/actions/update-user/update-user.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used

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;
},
};
101 changes: 96 additions & 5 deletions components/okta/okta.app.mjs
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,
});
},
},
};
};
2 changes: 1 addition & 1 deletion components/okta/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
"publishConfig": {
"access": "public"
}
}
}
62 changes: 62 additions & 0 deletions components/okta/sources/watch-new-events/watch-new-events.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { axios } from "@pipedream/platform";

Check failure on line 1 in components/okta/sources/watch-new-events/watch-new-events.mjs

View workflow job for this annotation

GitHub Actions / Lint Code Base

'axios' is defined but never used
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);
}
},
};

0 comments on commit afa839f

Please sign in to comment.