Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add polaris-web client library #87

Merged
merged 2 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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