Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed Oct 30, 2024
1 parent a60f7e4 commit 2e26c32
Show file tree
Hide file tree
Showing 10 changed files with 3,166 additions and 696 deletions.
9 changes: 9 additions & 0 deletions examples/express/with-m2m/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
![SuperTokens banner](https://raw.githubusercontent.com/supertokens/supertokens-logo/master/images/Artboard%20%E2%80%93%2027%402x.png)

# SuperTokens EmailPassword Demo app

To get this demo app, please run the following command:

```bash
npx create-supertokens-app@latest --recipe=emailpassword
```
672 changes: 0 additions & 672 deletions examples/express/with-m2m/assistant-client/package-lock.json

This file was deleted.

18 changes: 0 additions & 18 deletions examples/express/with-m2m/assistant-client/package.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"helmet": "^5.1.0",
"morgan": "^1.10.0",
"npm-run-all": "^4.1.5",
"supertokens-node": "github:supertokens/supertokens-node#21.0",
"supertokens-node": "file:../../../../lib/build",
"ts-node-dev": "^2.0.0",
"typescript": "^4.7.2"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/express/with-m2m/calendar-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function verifyAccessToken(requiredScope: string) {
} else {
res.status(403).send(`Forbidden: Missing required scope: ${requiredScope}`);
}
} catch (err) {
} catch (err: any) {
if (err.code === "ERR_JWT_CLAIM_VALIDATION_FAILED") {
if (err.claim === "aud") {
res.status(403).send("Forbidden: Invalid audience");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { readFile } from "fs/promises";
import { readFile } from "node:fs/promises";
import { Command } from "commander";

const authProviderBaseUrl = "http://localhost:3001";
const calendarServiceBaseUrl = "http://localhost:3011";
Expand Down Expand Up @@ -146,7 +147,7 @@ async function updateNote(accessToken: string, noteId: number, note: Partial<Omi
}

async function main() {
const file = await readFile("../clients.json", "utf-8");
const file = await readFile("./clients.json", "utf-8");
const clients = JSON.parse(file);
console.log(clients);
const { clientId, clientSecret } = clients.assistant;
Expand Down Expand Up @@ -178,4 +179,48 @@ async function main() {
console.log(await getNotes(accessToken));
}

main();
const program = new Command();

program.name("assistant-client").description("A client for the calendar and note services").version("1.0.0");

const calendarCommand = new Command("calendar").description("Interact with the calendar service");
calendarCommand.addCommand(
new Command("add")
.description("Add an event")
.option("-t, --title <title>", "The title of the event")
.option("-s, --start <start>", "The start time of the event")
.option("-e, --end <end>", "The end time of the event")
.action(async (options) => {
let clientId: string, clientSecret: string;
try {
const file = await readFile("./clients.json", "utf-8");
const clients = JSON.parse(file);
({ clientId, clientSecret } = clients.assistant);
} catch (error) {
console.error("Failed to read clients.json, please run npm start in the auth-provider-service directory", error);
return;
}

console.log(options);

if (options.args.length === 0) {
console.error("Please provide a description for the event");
return;
}

const accessToken = await getAccessToken(clientId, clientSecret, "calendar-service", "calendar.write");
console.log(await addEvent(accessToken, {
title: options.title ?? "Untitled Event",
start: options.start ? Date.parse(options.start) : Date.now(),
end: options.end ? Date.parse(options.end) : Date.now() + 1000 * 60 * 60,
description: options.args.join(" "),
}));
})
);

program.addCommand(calendarCommand);
program.addCommand(new Command("note").description("Interact with the note service"));

program.parse(process.argv);

// main();
2 changes: 1 addition & 1 deletion examples/express/with-m2m/note-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function verifyAccessToken(requiredScope: string) {
} else {
res.status(403).send("Forbidden: Invalid scope");
}
} catch (err) {
} catch (err: any) {
if (err.code === "ERR_JWT_CLAIM_VALIDATION_FAILED") {
if (err.claim === "aud") {
res.status(403).send("Forbidden: Invalid audience");
Expand Down
Loading

0 comments on commit 2e26c32

Please sign in to comment.