Skip to content

Commit

Permalink
use jose to verify the jwt
Browse files Browse the repository at this point in the history
  • Loading branch information
artlu99 committed Nov 3, 2024
1 parent 761c3f4 commit e9a4a80
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
18 changes: 17 additions & 1 deletion functions/getSassyHashes/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { PrivyClient } from '@privy-io/server-auth';
import { Client, fetchExchange, gql } from '@urql/core';
import { importSPKI, jwtVerify } from 'jose';

import { Env } from '../common';

Expand All @@ -21,9 +22,24 @@ const getFid = async (privyAuthToken: string, env: Env): Promise<number> => {
const privy = new PrivyClient(env.REACT_APP_PRIVY_APP_ID, env.PRIVY_APP_SECRET);

try {
// one-time bootstrap to see if we can extract the FID from the token
const privyVerificationKey = await privy.getVerificationKey();
const verificationKey = await importSPKI(privyVerificationKey, 'ES256');
console.log('privyVerificationKey:', privyVerificationKey);
console.log('verificationKey:', verificationKey);

try {
const payload = await jwtVerify(privyAuthToken, verificationKey, {
issuer: 'privy.io',
audience: env.REACT_APP_PRIVY_APP_ID || 'insert-your-privy-app-id',
});
console.log(payload);
} catch (error) {
console.error(error);
}

const verifiedClaims = await privy.verifyAuthToken(privyAuthToken);
const user = await privy.getUser(verifiedClaims.userId);
console.log('Privy User:', user);

// const user2 = await privy.getUser({ idToken: IDTokenFromCookies(request) });
return user?.farcaster?.fid;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"exponential-backoff": "^3.1.1",
"i18next": "^20.4.0",
"idb-keyval": "^6.2.1",
"jose": "^5.9.6",
"lucide-react": "^0.394.0",
"posthog-js": "^1.142.1",
"react": "^18.3.1",
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7760,6 +7760,7 @@ __metadata:
husky: ^9.0.11
i18next: ^20.4.0
idb-keyval: ^6.2.1
jose: ^5.9.6
less: ^4.2.0
less-plugin-clean-css: ^1.5.1
lint-staged: ^11.0.0
Expand Down Expand Up @@ -12058,6 +12059,13 @@ __metadata:
languageName: node
linkType: hard

"jose@npm:^5.9.6":
version: 5.9.6
resolution: "jose@npm:5.9.6"
checksum: 4b536da0201858ed4c4582e8bb479081f11e0c63dd0f5e473adde16fc539785e1f2f0409bc1fc7cbbb5b68026776c960b4952da3a06f6fdfff0b9764c9127ae0
languageName: node
linkType: hard

"joycon@npm:^3.1.1":
version: 3.1.1
resolution: "joycon@npm:3.1.1"
Expand Down

0 comments on commit e9a4a80

Please sign in to comment.