cloudflare / template-registry

A simple API via a Worker that serves all the template content
https://developers.cloudflare.com/workers/templates
Apache License 2.0
62 stars 37 forks source link

Web Crypto API support in Sign and Verify Snippet #47

Closed bradyjoslin closed 4 years ago

bradyjoslin commented 4 years ago

Update the signed_requested.js snippet that demonstrates signing and verifying HMAC tokens to use the Web Crypto API instead of require("crypto").

Web Crypto is natively supported by the Workers Runtime and allows you to sign and verify with plain JavaScript workers instead of needing to use webpack.

Additionally, the developer documentation on the Web Crypto API for Workers mentions using the API for signing and verifying:

This API is commonly used for signing requests

But that link just redirects to the home page for the Cloudflare Workers documentation. This snippet could provide a landing spot for that link for those interested in learning more.

bradyjoslin commented 4 years ago

Noticed PR https://github.com/cloudflare/template-registry/pull/46 is already open for adding web crypto examples after submitting this one. However, that appears to be for a new snippet instead of updating signed_request.js. Nevertheless, if you don't believe it makes sense to have two examples showing how to sign/verify using web crypto and want to use the other one instead, I'd understand. Would recommend at minimum referring to the web crypto example from the comments for this existing snippet to make it clear there's another way.

bradyjoslin commented 4 years ago

Was reviewing the new docs site this morning and saw there are a few pages that do a great job describing signing requests:

Since this topic seems very well covered, I'm going to go ahead and close this PR.