Skip to content

Commit

Permalink
Merge pull request #87 from HunnySajid/feat/polaris-web-client
Browse files Browse the repository at this point in the history
feat: add polaris-web client library
  • Loading branch information
rodolfomiranda committed Feb 7, 2024
2 parents eeaeb0e + f22042c commit a98e8e9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 167 deletions.
117 changes: 6 additions & 111 deletions example-web/my-app/package-lock.json

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

1 change: 1 addition & 0 deletions example-web/my-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"eslint": "^8.56.0",
"polaris-web": "^1.0.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-scripts": "5.0.1",
Expand Down
76 changes: 20 additions & 56 deletions example-web/my-app/src/App.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,24 @@
import {
requestAid,
requestCredential,
requestAidORCred,
attemptAutoSignin,
} from "polaris-web";
import logo from "./ACME_Corporation.png";
import Button from "@mui/material/Button";
import "./App.css";

var extensionId = "";

function App() {

window.addEventListener(
"message",
async (event) => {
// Accept messages only from same window
if (event.source !== window) {
return;
}

if (event.data.type && event.data.type === "signify-extension") {
console.log("Content scrip loaded");
extensionId = event.data.data.extensionId;
const handleAutoSignin = async () => {
try {
const resp = await attemptAutoSignin();
if (resp?.data) {
alert(
"Signed headers received\n" +
JSON.stringify(resp?.data.headers, null, 2)
);
}
},
false
);

const handleRequestIdentifier = () => {
window.postMessage({ type: "select-identifier" }, "*");
};

const handleRequestCredential = () => {
window.postMessage({ type: "select-credential" }, "*");
};

const handleRequestIdORCred = () => {
window.postMessage({ type: "select-aid-or-credential" }, "*");
};

const handleRequestAutoSignin = () => {
window.postMessage({ type: "select-auto-signin" }, "*");
};

const handleSyncRequest = async () => {
const { data, error } = await chrome.runtime.sendMessage(extensionId, {
type: "fetch-resource",
subtype: "auto-signin-signature",
});

if (error) {
handleRequestAutoSignin();
} else {
alert(
"Signed headers received\n" + JSON.stringify(data.headers, null, 2)
);
}
} catch (error) {}
};

return (
Expand All @@ -59,33 +27,29 @@ function App() {
<img src={logo} alt="logo" />
<div className="flex flex-col gap-y-2 mt-2">
<p className=" text-lg font-bold">Authenticate with</p>
<Button
variant="contained"
color="success"
onClick={handleRequestIdentifier}
>
<Button variant="contained" color="success" onClick={requestAid}>
AID
</Button>
<Button
variant="contained"
color="success"
onClick={handleRequestCredential}
onClick={requestCredential}
>
Credential
</Button>
<Button
variant="contained"
color="success"
onClick={handleRequestIdORCred}
onClick={requestAidORCred}
>
AID or CRED
</Button>
<Button
variant="contained"
color="success"
onClick={handleSyncRequest}
onClick={handleAutoSignin}
>
Synchronous
Auto Sign in
</Button>
</div>
</header>
Expand Down

0 comments on commit a98e8e9

Please sign in to comment.