feat/push-notifications #34
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "BordedDev/snek:feat/push-notifications"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This is the current push notifications code. It uses the full payload rather than the signal type. It creates needed certs and doesn't require any third-party libs outside the cryptography library
@ -65,0 +51,4 @@
console.log("Notification closed", event);
})
self.addEventListener("fetch", (event) => {
Only added because somewhere while reading this was a requirement on some browsers to get push notifications to work with WPAs
@ -0,0 +20,4 @@
PRIVATE_KEY_FILE = Path("./notification-private.pem")
PRIVATE_KEY_PKCS8_FILE = Path("./notification-private.pkcs8.pem")
PUBLIC_KEY_FILE = Path("./notification-public.pem")
These keys need to be persisted because the public key is sent to the browser's PushNotification service.
The reason for the PKCS8 file is just for debugging and can be removed
@ -31,0 +8,4 @@
const keyResponse = await fetch('/push.json')
const keyData = await keyResponse.json()
const publicKey = Uint8Array.from(atob(keyData.publicKey), c => c.charCodeAt(0))
In the future this can be replaced with
Uint8Array.fromBase64()
It's just not available in chrome/old firefox ;PThen it's easy, i prefer this. Because let's face it, that frombase64 code doesn't do so much. Don't see a reason to exclude browsers for such simple functionality.
@ -0,0 +149,4 @@
salt = os.urandom(16)
user_key_bytes = base64.urlsafe_b64decode(p256dh + "==")
Python base64 parsing discards excessive padding (
=
) but will not add it if it's missing, causing it to think the base64 is bad if it isn't 4 char aligned@ -31,0 +52,4 @@
}
});
};
registerServiceWorker(true).catch(console.error);
Some browsers will show the permission prompt immediately, others require a "registered" interaction
5a5d1cb3dd
to272998f757