Skip to content

Commit

Permalink
feat(embed): fix challenge endpoint, pass providers for verify (#3305)
Browse files Browse the repository at this point in the history
  • Loading branch information
larisa17 authored Feb 25, 2025
1 parent a93cab1 commit 1dbdad6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
14 changes: 9 additions & 5 deletions embed-popup/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,18 @@ function App() {
const state = urlParams.get("state");
const address = urlParams.get("address");
const platform = urlParams.get("platform");
const providers = urlParams.get("providers");
const signature = urlParams.get("signature");
const credential = urlParams.get("credential");
const scorerId = urlParams.get("scorerId");

if (address && signature && credential && platform && scorerId) {
if (address && signature && credential && platform && providers && scorerId) {
// preserve the values in local storage
// when the OAuth flow is complete, the code will be present but the address, signature, platform and credential will be null
// so we only store them in the localStorage if they are not null.
localStorage.setItem("address", address);
localStorage.setItem("platform", platform);
localStorage.setItem("providers", providers);
localStorage.setItem("signature", signature);
localStorage.setItem("credential", credential);
localStorage.setItem("scorerId", scorerId);
Expand Down Expand Up @@ -114,13 +116,14 @@ function App() {
const _signature = localStorage.getItem("signature");
const _credential = localStorage.getItem("credential") || "";
const _platform = localStorage.getItem("platform") || "";
const _providers = localStorage.getItem("providers") || "";
const _scorerId = localStorage.getItem("scorerId") || "";

try {
const payload = {
payload: {
type: _platform || "unknown", // Ensure type is a string
types: [_platform || "unknown"], // Ensure types contains strings
types: _providers,
version: "0.0.0",
address: _address || "unknown",
proofs: {
Expand Down Expand Up @@ -165,7 +168,7 @@ function App() {
data: {
payload: {
type: string;
types: string[];
types: string;
version: string;
address: string;
proofs: { code: string; sessionKey: string };
Expand All @@ -174,9 +177,10 @@ function App() {
scorerId: string;
}
): Promise<VerificationResponseType | null> => {
let parsedChallenge;
let parsedChallenge, parsedTypes;
try {
parsedChallenge = data.challenge ? JSON.parse(data.challenge) : null;
parsedTypes = data.payload.types ? JSON.parse(data.payload.types) : null;
} catch (error) {
setStep("Error parsing local storage values.");
setErrorMessages(`Invalid JSON format in local storage. ${error}`);
Expand All @@ -189,7 +193,7 @@ function App() {
"Content-Type": "application/json",
},
body: JSON.stringify({
payload: { ...data.payload },
payload: { ...data.payload, types: parsedTypes },
challenge: parsedChallenge,
scorerId: data.scorerId,
}),
Expand Down
2 changes: 1 addition & 1 deletion embed/src/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ export const getChallengeHandler = (
// generate a VC for the given payload
return void issueChallengeCredential(
DIDKit,
issuer.did,
issuer.key,
record,
payload.signatureType,
)
Expand Down

0 comments on commit 1dbdad6

Please sign in to comment.