Skip to content

Commit

Permalink
Merge pull request #117 from HunnySajid/feat/firefox-compatibility
Browse files Browse the repository at this point in the history
feat: make requestAutoSignin compatible with firefox
  • Loading branch information
HunnySajid committed Mar 1, 2024
2 parents b4c3367 + bf82b76 commit 7fa90d1
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 220 deletions.
2 changes: 1 addition & 1 deletion example-web/my-app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions example-web/my-app/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import {
requestCredential,
requestAidORCred,
trySettingVendorUrl,
} from "./signify-polaris-web";
canCallAsync,
} from "signify-polaris-web";
import Button from "@mui/material/Button";
import Alert from "@mui/material/Alert";
import CircularProgress from "@mui/material/CircularProgress";
Expand Down Expand Up @@ -66,6 +67,18 @@ function App() {
setParsedSignifyData(null);
};

const handleRequestAutoSignin = async () => {
console.log("canCallAsync()", canCallAsync());
if (canCallAsync()) {
const resp = await requestAutoSignin();
if (resp) {
handleSignifyData(resp);
}
} else {
requestAutoSignin();
}
};

const renderData = () => {
if (extensionInstalled === null) return <CircularIndeterminate />;

Expand Down Expand Up @@ -93,7 +106,7 @@ function App() {
<Button
variant="contained"
color="success"
onClick={requestAutoSignin}
onClick={handleRequestAutoSignin}
>
Auto Sign in
</Button>
Expand Down
105 changes: 0 additions & 105 deletions example-web/my-app/src/signify-polaris-web/index.js

This file was deleted.

51 changes: 0 additions & 51 deletions example-web/my-app/src/signify-polaris-web/pubsub.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/components/credentialList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function CredentialList(): JSX.Element {
</div>
))}
{!isLoading && !credentials?.length ? (
<p className="">{formatMessage({ id: "message.noItems" })}</p>
<p className="text-xs">{formatMessage({ id: "message.noItems" })}</p>
) : (
<></>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/identifierList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function IdentifierList(): JSX.Element {
</div>
))}
{!isLoading && !aids?.length ? (
<p className="">{formatMessage({ id: "message.noItems" })}</p>
<p className="text-xs">{formatMessage({ id: "message.noItems" })}</p>
) : (
<></>
)}
Expand Down
2 changes: 1 addition & 1 deletion src/components/signinList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function SigninList(): JSX.Element {
</div>
))}
{!isLoading && !signins?.length ? (
<p className="">{formatMessage({ id: "message.noItems" })}</p>
<p className="text-xs">{formatMessage({ id: "message.noItems" })}</p>
) : (
<></>
)}
Expand Down
85 changes: 28 additions & 57 deletions src/pages/background/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ chrome.runtime.onMessage.addListener(function (
// Validate that message comes from a page that has a signin
const origin = removeSlash(sender.url);
const signins = await getSigninsByDomain(origin);
console.log("signins", signins);
const autoSignin = signins?.find((signin) => signin.autoSignin);
if (!signins?.length || !autoSignin) {
sendResponse({
Expand Down Expand Up @@ -318,63 +317,35 @@ chrome.runtime.onMessageExternal.addListener(function (
console.log("Message received from external source: ", sender);
console.log("Message received from external request: ", message);

// if (
// message.type === "fetch-resource" &&
// message.subtype === "auto-signin-signature"
// ) {
// // Validate that message comes from a page that has a signin
// const origin = removeSlash(sender.url);
// const signins = await getSigninsByDomain(origin);
// console.log("signins", signins);
// const autoSignin = signins?.find((signin) => signin.autoSignin);
// if (!signins?.length || !autoSignin) {
// sendResponse({
// error: { code: 404, message: "auto signin not found" },
// });
// return;
// }

// const signedHeaders = await signifyService.signHeaders(
// // sigin can either have identifier or credential
// autoSignin?.identifier
// ? autoSignin?.identifier?.name
// : autoSignin?.credential?.issueeName,
// origin
// );
// let jsonHeaders: { [key: string]: string } = {};
// for (const pair of signedHeaders.entries()) {
// jsonHeaders[pair[0]] = pair[1];
// }
// sendResponse({ data: { headers: jsonHeaders } });
// }


// if (
// message.type === "vendor-info" &&
// message.subtype === "attempt-set-vendor-url"
// ) {
// const { vendorUrl } = message?.data ?? {};
// if (!vendorUrl) {
// return;
// }

// const _vendorUrl = await configService.getUrl();
// if (!_vendorUrl) {
// try {
// const resp = await (await fetch(vendorUrl)).json();
// if (resp?.agentUrl) {
// await configService.setAgentUrl(resp?.agentUrl);
// }
// await configService.setData(resp);
// if (resp?.icon) {
// await setActionIcon(resp?.icon);
// }
// await configService.setUrl(vendorUrl);
// } catch (error) {}
// }
if (
message.type === "fetch-resource" &&
message.subtype === "auto-signin-signature"
) {
// Validate that message comes from a page that has a signin
const origin = removeSlash(sender.url);
const signins = await getSigninsByDomain(origin);
console.log("signins", signins);
const autoSignin = signins?.find((signin) => signin.autoSignin);
if (!signins?.length || !autoSignin) {
sendResponse({
error: { code: 404, message: "auto signin not found" },
});
return;
}

// sendResponse({ data: { _vendorUrl } });
// }
const signedHeaders = await signifyService.signHeaders(
// sigin can either have identifier or credential
autoSignin?.identifier
? autoSignin?.identifier?.name
: autoSignin?.credential?.issueeName,
origin
);
let jsonHeaders: { [key: string]: string } = {};
for (const pair of signedHeaders.entries()) {
jsonHeaders[pair[0]] = pair[1];
}
sendResponse({ data: { headers: jsonHeaders } });
}
})();

// return true to indicate chrome api to send a response asynchronously
Expand Down
1 change: 0 additions & 1 deletion src/pages/content/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ window.addEventListener(
{ type: "signify-signature", data: data },
"*"
);
// pubsub.publish("signify-signature", data);
}
}

Expand Down

0 comments on commit 7fa90d1

Please sign in to comment.