-
Notifications
You must be signed in to change notification settings - Fork 7
Add example TypeScript app for Audit Logs #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
logangingerich
merged 5 commits into
main
from
feature/sup-759-typescript-add-example-app-for-audit
Oct 24, 2022
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c8ffa67
Add Typescript Audit Logs Example App
logangingerich 3f92e12
README update
logangingerich 27939f6
remove console.log statements
logangingerich ca55f11
Node to TypeScript updates
logangingerich 97cfdcb
Update README.md
logangingerich File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,4 @@ | ||
node_modules | ||
.env | ||
out/ | ||
tsconfig.tsbuildinfo |
This file contains hidden or 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,74 @@ | ||
# TypeScript Example App with Audit Logs powered by WorkOS | ||
|
||
An example Node.js / TypeScript application demonstrating how to use the [WorkOS Node.js SDK](https://github.com/workos/workos-node) to send and retrieve Audit Log events. This app is not meant to show a real-world example of an Audit Logs implementation, but rather to show concrete examples of how events can be sent using the Node.js SDK. | ||
|
||
## Prerequisites | ||
|
||
-Node.js version 10+ | ||
|
||
## Node Project Setup | ||
|
||
1. Clone the main repo and install dependencies for the app you'd like to use: | ||
|
||
```bash | ||
# HTTPS | ||
git clone https://github.com/workos/typescript-example-applications.git | ||
``` | ||
|
||
or | ||
|
||
```bash | ||
# SSH | ||
git clone git@github.com:workos/typescript-example-applications.git | ||
``` | ||
|
||
2. Navigate to Audit Logs app within the cloned repo. | ||
|
||
```bash | ||
$ cd typescript-example-applications/typescript-audit-logs-example | ||
``` | ||
|
||
3. Install the dependencies. | ||
```bash | ||
$ npm install | ||
``` | ||
|
||
## Configure your environment | ||
|
||
4. Grab your API Key and Client ID from the WorkOS Dashboard. Create a `.env` | ||
file at the root of the project, and store these like so: | ||
|
||
```bash | ||
WORKOS_API_KEY=sk_xxxxxxxxxxxxx | ||
WORKOS_CLIENT_ID=project_xxxxxxxxxxxx | ||
``` | ||
|
||
## Testing the Integration | ||
|
||
5. Start the server and head to `http://localhost:8000/ to begin the login flow! | ||
|
||
```sh | ||
npm start | ||
``` | ||
|
||
## Audit Logs setup | ||
|
||
Follow the [Audit Logs configuration steps](https://workos.com/docs/audit-logs/emit-an-audit-log-event/sign-in-to-your-workos-dashboard-account-and-configure-audit-log-event-schemas) to set up the following 5 events that are sent with this example: | ||
|
||
Action title: "user.signed_in" | Target type: "team" | ||
Action title: "user.logged_out" | Target type: "team" | ||
Action title: "user.organization_set" | Target type: "team" | ||
Action title: "user.organization_deleted" | Target type: "team" | ||
Action title: "user.connection_deleted" | Target type: "team" | ||
|
||
Next, take note of the Organization ID for the Org which you will be sending the Audit Log events for. This ID gets entered into the splash page of the example application. | ||
|
||
Once you enter the Organization ID and submit it, you will be brought to the page where you'll be able to send the audit log events that were just configured. You'll also notice that the action of setting the Organization triggered an Audit Log already. Click the buttons to send the respective events. | ||
|
||
To obtain a CSV of the Audit Log events that were sent for the last 30 days, click the "Export Events" button. This will bring you to a new page where you can download the events. Downloading the events is a 2 step process. First you need to create the report by clicking the "Generate CSV" button. Then click the "Access CSV" button to download a CSV of the Audit Log events for the selected Organization for the past 30 days. | ||
|
||
## Need help? | ||
|
||
First, make sure to reference the Audit Logs docs at https://workos.com/docs/audit-logs. | ||
|
||
If you get stuck and aren't able to resolve the issue by reading our docs or API reference, you can reach out to us at support@workos.com and we'll lend a hand. |
This file contains hidden or 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,96 @@ | ||
const user_signed_in = { | ||
"action": "user.signed_in", | ||
"occurred_at": new Date().toISOString(), | ||
"actor": { | ||
"type": "user", | ||
"id": "user_01GBNJC3MX9ZZJW1FSTF4C5938", | ||
}, | ||
"targets": [ | ||
{ | ||
"type": "team", | ||
"id": "team_01GBNJD4MKHVKJGEWK42JNMBGS", | ||
}, | ||
], | ||
"context": { | ||
"location": "123.123.123.123", | ||
"user_agent": "Chrome/104.0.0.0", | ||
}, | ||
} | ||
|
||
const user_logged_out = { | ||
"action": "user.logged_out", | ||
"occurred_at": new Date().toISOString(), | ||
"actor": { | ||
"type": "user", | ||
"id": "user_01GBNJC3MX9ZZJW1FSTF4C5938", | ||
}, | ||
"targets": [ | ||
{ | ||
"type": "team", | ||
"id": "team_01GBNJD4MKHVKJGEWK42JNMBGS", | ||
}, | ||
], | ||
"context": { | ||
"location": "123.123.123.123", | ||
"user_agent": "Chrome/104.0.0.0", | ||
}, | ||
} | ||
|
||
const user_organization_set = { | ||
"action": "user.organization_set", | ||
"occurred_at": new Date().toISOString(), | ||
"actor": { | ||
"type": "user", | ||
"id": "user_01GBNJC3MX9ZZJW1FSTF4C5938", | ||
}, | ||
"targets": [ | ||
{ | ||
"type": "team", | ||
"id": "team_01GBNJD4MKHVKJGEWK42JNMBGS", | ||
}, | ||
], | ||
"context": { | ||
"location": "123.123.123.123", | ||
"user_agent": "Chrome/104.0.0.0", | ||
}, | ||
} | ||
|
||
const user_organization_deleted = { | ||
"action": "user.organization_deleted", | ||
"occurred_at": new Date().toISOString(), | ||
"actor": { | ||
"type": "user", | ||
"id": "user_01GBNJC3MX9ZZJW1FSTF4C5938", | ||
}, | ||
"targets": [ | ||
{ | ||
"type": "team", | ||
"id": "team_01GBNJD4MKHVKJGEWK42JNMBGS", | ||
}, | ||
], | ||
"context": { | ||
"location": "123.123.123.123", | ||
"user_agent": "Chrome/104.0.0.0", | ||
}, | ||
} | ||
|
||
const user_connection_deleted = { | ||
"action": "user.connection_deleted", | ||
"occurred_at": new Date().toISOString(), | ||
"actor": { | ||
"type": "user", | ||
"id": "user_01GBNJC3MX9ZZJW1FSTF4C5938", | ||
}, | ||
"targets": [ | ||
{ | ||
"type": "team", | ||
"id": "team_01GBNJD4MKHVKJGEWK42JNMBGS", | ||
}, | ||
], | ||
"context": { | ||
"location": "123.123.123.123", | ||
"user_agent": "Chrome/104.0.0.0", | ||
}, | ||
} | ||
|
||
module.exports = { user_signed_in, user_logged_out, user_organization_set, user_organization_deleted, user_connection_deleted }; |
This file contains hidden or 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,22 @@ | ||
const express = require('express') | ||
import 'dotenv/config.js' | ||
const router = require('./routes/index.ts') | ||
import morgan from 'morgan' | ||
|
||
const app = express() | ||
|
||
const port = process.env.PORT || 8000 | ||
|
||
app.use('/public', express.static('public')) | ||
|
||
app.use(express.urlencoded({ extended: false })) | ||
|
||
app.use(express.json()) | ||
|
||
app.use(morgan('dev')) | ||
|
||
app.use('/', router) | ||
|
||
app.listen(port, () => { | ||
console.log(`⚡️ [server]: Server is running at https://localhost:${port}`) | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more I think we'll want to change to TypeScript