Skip to content

Commit

Permalink
feat(app): request unique nonce from server for authentication (passp…
Browse files Browse the repository at this point in the history
…ortxyz#989)

* feat(app): request unique nonce from server for authentication

* fix(app,lint): run prettier on file
  • Loading branch information
nutrina authored Feb 20, 2023
1 parent 73882bb commit c3e9cc0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions app/context/userContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,18 @@ export const UserContextProvider = ({ children }: { children: any }) => {
};

const getPassportDatabaseAccessToken = async (did: DID): Promise<string> => {
// TODO: set a meaningfull payload ...
const payloadToSign = { data: "TODO" };
let nonce = null;
try {
// Get nonce from server
const nonceResponse = await axios.get(`${process.env.NEXT_PUBLIC_CERAMIC_CACHE_ENDPOINT}account/nonce`);
nonce = nonceResponse.data.nonce;
} catch (error) {
const msg = `Failed to get nonce from server for user with did: ${did.parent}`;
datadogRum.addError(msg);
throw msg;
}

const payloadToSign = { nonce };

// sign the payload as dag-jose
const { jws, cacaoBlock } = await did.createDagJWS(payloadToSign);
Expand All @@ -142,6 +152,7 @@ export const UserContextProvider = ({ children }: { children: any }) => {
cid: Array.from(link ? link.bytes : []),
cacao: Array.from(cacaoBlock ? cacaoBlock : []),
issuer,
nonce: nonce,
};

try {
Expand Down

0 comments on commit c3e9cc0

Please sign in to comment.