Skip to content

Commit ce0910c

Browse files
committed
feat: Fix JS demo page to remove "aud"
"aud" was misidentified as a requirement, and to point to the wrong host. Added text to various usage calls to indicate that you can use your own tags and values, and why you might want to do that. Also added link to "demo" page for the vapid JS form. Closes #17
1 parent 39a7d23 commit ce0910c

File tree

5 files changed

+25
-20
lines changed

5 files changed

+25
-20
lines changed

js/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ and verify VAPID headers.
55

66
The index.html file contains a stand-alone generator/verifier.
77

8+
[live demo](https://web-push-libs.github.io/vapid/js/)

js/index.html

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@ <h1>VAPID verification</h1>
5252
<div id="result" class="section">
5353
<a name="claims"><h2>Claims</h2></a>
5454
<p>Claims are the information a site uses to identify itself.
55-
<div class="row">
56-
<label for="aud" title="The full URL to your site."><b>Aud</b>ience:</label>
57-
<p>The optional full URL to your site.</p>
58-
<input name="aud" placeholder="https://push.example.com">
59-
</div>
6055
<div class="row">
6156
<label for="sub" ><b>Sub</b>scriber:</label>
6257
<p>The required administrative email address that can be contacted if there's an issue</p>
@@ -67,6 +62,17 @@ <h1>VAPID verification</h1>
6762
<p>Time in seconds for this claim to live. (Default/Max: 24 hours from now)</p>
6863
<input name="exp" id="vapid_exp" placeholder="Time in seconds">
6964
</div>
65+
<p>&nbsp;</p>
66+
<p><b><i>Note</i></b>: You can add more claims if you wish.
67+
These can include things
68+
like, the ID of the originating server (if you have several that may be
69+
publishing updates), a proxied customer ID or hash (for privacy reasons,
70+
you probably don't want to make this easily determinable), or any other
71+
value that may be useful between the Push Server Ops team and yours.
72+
Just make the values short so you don't run the risk of the server
73+
rejecting a request because the headers are too big.</p>
74+
<p>For example:
75+
<code>{'ami_id':'e-1248296','cust_id':'a9afd519s919faio3'}</code></p>
7076
<div class="control">
7177
<button id="gen">Generate VAPID</button>
7278
</div>
@@ -124,7 +130,7 @@ <h3>Claims JSON object:</h3>
124130
}
125131

126132
function success(claims) {
127-
for (let n of ["aud", "sub", "exp"]) {
133+
for (let n of ["sub", "exp"]) {
128134
let item = document.getElementsByName(n)[0];
129135
item.value = claims[n];
130136
item.classList.add("updated");
@@ -171,15 +177,6 @@ <h3>Claims JSON object:</h3>
171177
reply[item.name] = item.value;
172178
}
173179

174-
// verify aud
175-
if (! /^https?:\/\//.test(reply['aud'])) {
176-
error(null,
177-
`Invalid Audience: Use the full URL of your site e.g. "http://example.com"`);
178-
document.getElementsByName("aud")[0].classList.add("err");
179-
err = true;
180-
} else {
181-
document.getElementsByName("aud")[0].classList.remove("err");
182-
}
183180
// verify sub
184181
if (! /^mailto:.+@.+/.test(reply['sub'])) {
185182
error(null,
@@ -227,7 +224,9 @@ <h3>Claims JSON object:</h3>
227224
}
228225
try {
229226
let rclaims = document.getElementById("raw_claims");
230-
rclaims.innerHTML = JSON.stringify(claims, null, " ");
227+
let sc = JSON.stringify(claims, null, 4);
228+
console.debug(sc);
229+
rclaims.innerHTML = sc;
231230
rclaims.classList.add("updated");
232231
vapid.generate_keys().then(x => {
233232
vapid.sign(claims)

python/claims.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
{
2-
"aud": "https://catfacts.example.com",
32
"sub": "mailto:[email protected]"
43
}

python/py_vapid/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import logging
1111
from jose import jws
1212

13-
__version__ = "0.2"
13+
__version__ = "0.3"
1414

1515

1616
class VapidException(Exception):

python/py_vapid/main.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,22 +49,28 @@ def main():
4949
information that describes you. There are three elements in the claims
5050
file you'll need:
5151
52-
"aud" This is your site's URL (e.g. "https://example.com")
5352
"sub" This is your site's admin email address
5453
(e.g. "mailto:[email protected]")
5554
"exp" This is the expiration time for the claim in seconds. If you don't
5655
have one, I'll add one that expires in 24 hours.
5756
57+
You're also welcome to add additional fields to the claims which could be
58+
helpful for the Push Service operations team to pass along to your operations
59+
team (e.g. "ami-id": "e-123456", "cust-id": "a3sfa10987"). Remember to keep
60+
these values short to prevent some servers from rejecting the transaction due
61+
to overly large headers. See https://jwt.io/introduction/ for details.
62+
5863
For example, a claims.json file could contain:
5964
60-
{"aud": "https://example.com", "sub": "mailto:[email protected]"}
65+
{"sub": "mailto:[email protected]"}
6166
"""
6267
exit
6368
try:
6469
claims = json.loads(open(claim_file).read())
6570
result = vapid.sign(claims)
6671
except Exception, exc:
6772
print "Crap, something went wrong: %s", repr(exc)
73+
raise exc
6874

6975
print "Include the following headers in your request:\n"
7076
for key, value in result.items():

0 commit comments

Comments
 (0)