Skip to content

Commit

Permalink
feat: add nonce check
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew-affinidi committed Sep 24, 2024
1 parent 0cc1dfa commit 5cbdd39
Show file tree
Hide file tree
Showing 25 changed files with 1,851 additions and 1,409 deletions.
902 changes: 470 additions & 432 deletions generator/nextjs/template/package-lock.json

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions generator/nextjs/template/src/components/NavBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@ const NavBar: FC = () => {
className="py-4 font-medium transition-colors hover:text-blue-500"
prefetch={false}
>
Receive Credentials
Receive Credentials (WS)
</Link>
<Link
href="/iota-redirect"
className="py-4 font-medium transition-colors hover:text-blue-500"
prefetch={false}
>
Redirect flow
Receive Credentials (Redirect)
</Link>
</nav>
{session && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export default function IotaCallbackPage() {
const responseCode = searchParams.get("response_code");

const iotaRedirectString = localStorage.getItem("iotaRedirect") || "";
const iotaRedirect = JSON.parse(iotaRedirectString);

const iotaResponseQuery = useQuery({
queryKey: ["queryOptions", iotaRedirectString],
Expand All @@ -42,7 +43,8 @@ export default function IotaCallbackPage() {
return (
<div>
<h1>Data Loaded:</h1>
<pre>{JSON.stringify(iotaResponseQuery.data, null, 2)}</pre>
<pre>Nonce matched: {iotaRedirect.nonce === iotaResponseQuery.data.nonce ? '✅' : '❌'}</pre>
<pre>Full response: {JSON.stringify(iotaResponseQuery.data, null, 2)}</pre>
</div>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,24 +64,25 @@ export default function IotaRedirectFlowPage({

async function handleRedirectFlowShare(queryId: string) {
setIsFormDisabled(true);

const nonce = uuidv4().slice(0, 10);
const response = await fetch("/api/iota/init-share", {
method: "POST",
body: JSON.stringify({
configurationId: selectedConfigId,
queryId,
redirectUri: selectedRedirectUri,
nonce: uuidv4().slice(0, 10),
nonce: nonce,
}),
headers: {
"Content-Type": "application/json",
"Accept": "application/json",
Accept: "application/json",
},
});

const data = await response.json();

const toStore = {
nonce,
configurationId: selectedConfigId,
correlationId: data.correlationId,
transactionId: data.transactionId,
Expand Down
2 changes: 1 addition & 1 deletion generator/nextjs/template/src/lib/clients/iota.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ export async function fetchIotaVpResponse(
});

const vp = JSON.parse((iotaVpResponse.data as any).vpToken);
return vp;
return { vp: vp, nonce: iotaVpResponse.data.nonce };
}
Binary file not shown.
Loading

0 comments on commit 5cbdd39

Please sign in to comment.