Skip to content

Commit b3dbe6d

Browse files
committed
Add JS draft2 fanciness
1 parent f9dea89 commit b3dbe6d

File tree

3 files changed

+41
-26
lines changed

3 files changed

+41
-26
lines changed

js/index.html

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,16 @@ <h1>VAPID verification</h1>
3737
<div class="description">This is the content of the
3838
<code>Authorization</code> header included as part of the subscription
3939
POST update.</div>
40-
<textarea name="auth" placeholder="Bearer abCDef..."></textarea>
40+
<textarea name="auth" id="auth" placeholder="WebPush abCDef..."></textarea>
41+
<div class="v1">
4142
<label for="crypt">Crypto-Key Header:</label>
4243
<div class="description">This is included
4344
as part of the <code>Crypto-Key</code> header, which is included
4445
as part of the subscription POST update. <code>Crypto-Key</code>
4546
may contain more than one part. Each part should be separated by a
4647
comma (",") (NOTE: For Draft-02, this header is not required)</div>
4748
<textarea name="crypt" placeholder="p256ecdsa=abCDef.."></textarea>
48-
<div class="control">
49-
<label for="publicKey">Public Key:</label>
50-
<div class="description">This is the VAPID key you would use when adding
51-
applications to your Dashboard.</div>
52-
<div name="publicKey" class="value" ></div>
49+
</div>
5350
<button id="check">Check headers</button>
5451
</div>
5552
</div>
@@ -82,14 +79,7 @@ <h1>VAPID verification</h1>
8279
<button id="gen">Generate VAPID</button>
8380
</div>
8481
<h3>Claims JSON object:</h3>
85-
<pre class="brush: js line-numbers lanuage-js">
86-
<code id="raw_claims" >None</code>
87-
</pre>
88-
<div id="ignored" class="hidden">
89-
<div class="title">The following were ignored.
90-
<div class="items"></div>
91-
</div>
92-
</div>
82+
<pre class="brush: js line-numbers lanuage-js"><code id="raw_claims" >None</code></pre>
9383
</div>
9484
<div id="keys" class="section">
9585
<a name="export"><h2>Exported Keys</h2></a>
@@ -127,6 +117,26 @@ <h3>Claims JSON object:</h3>
127117
return new VapidToken02();
128118
}
129119

120+
function vers_click(e) {
121+
if (document.getElementById('version').getElementsByTagName('input')[0].checked) {
122+
document.getElementById('auth').placeholder="WebPush abCDef...";
123+
for (item of document.getElementsByClassName('v2')) {
124+
item.classList.add('hidden')
125+
}
126+
for (item of document.getElementsByClassName('v1')) {
127+
item.classList.remove('hidden')
128+
}
129+
} else {
130+
document.getElementById('auth').placeholder="vapid t=abCDef..., k=aBcD...";
131+
for (item of document.getElementsByClassName('v1')) {
132+
item.classList.add('hidden')
133+
}
134+
for (item of document.getElementsByClassName('v2')) {
135+
item.classList.remove('hidden')
136+
}
137+
}
138+
}
139+
130140
function error(ex=null, msg=null, clear=false) {
131141
let er = document.getElementById("err");
132142
if (clear) {
@@ -142,6 +152,7 @@ <h3>Claims JSON object:</h3>
142152
}
143153

144154
function success(claims) {
155+
document.getElementById('raw_claims').innerHTML = JSON.stringify(claims, null, 2);
145156
for (let n of ["sub", "exp"]) {
146157
let item = document.getElementsByName(n)[0];
147158
item.value = claims[n];
@@ -151,13 +162,6 @@ <h3>Claims JSON object:</h3>
151162
let err = document.getElementById("err");
152163
err.innerHTML = "";
153164
err.classList.add("hidden");
154-
let extra = JSON.stringify(claims, " ");
155-
if (extra.length > 2) {
156-
let ignored = document.getElementsById("ignored");
157-
ignored.getElementsByClassName("items")
158-
.innerHTML = extra;
159-
ignored.classList.remove("hidden");
160-
}
161165
}
162166

163167

@@ -304,6 +308,8 @@ <h3>Claims JSON object:</h3>
304308
}
305309
}
306310

311+
312+
document.getElementById("version").addEventListener("click", vers_click);
307313
document.getElementById("check").addEventListener("click", check);
308314
document.getElementById("gen").addEventListener("click", gen);
309315
document.getElementById('vapid_exp').value = parseInt(Date.now()*.001) + 86400;

python/claims.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
{
2-
"sub": "mailto:[email protected]"
2+
"sub": "mailto:[email protected]",
3+
"aud": "https://push.services.mozilla.com",
4+
"exp": "1463001340"
35
}
6+

python/py_vapid/main.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ def main():
2525
help="show applicationServerKey value",
2626
default=False, action="store_true")
2727
args = parser.parse_args()
28+
29+
# Added to solve 2.7 => 3.* incompatibility
30+
try:
31+
input = raw_input
32+
except NameError:
33+
pass
2834
Vapid = Vapid01
2935
if args.version2:
3036
Vapid = Vapid02
@@ -33,8 +39,8 @@ def main():
3339
print("No private_key.pem file found.")
3440
answer = None
3541
while answer not in ['y', 'n']:
36-
answer = raw_input("Do you want me to create one for you? "
37-
"(Y/n)")
42+
answer = input("Do you want me to create one for you? "
43+
"(Y/n)")
3844
if not answer:
3945
answer = 'y'
4046
answer = answer.lower()[0]
@@ -50,8 +56,8 @@ def main():
5056
"the developer dashboard.")
5157
answer = None
5258
while answer not in ['y', 'n']:
53-
answer = raw_input("Do you want me to create one for you? "
54-
"(Y/n)")
59+
answer = input("Do you want me to create one for you? "
60+
"(Y/n)")
5561
if not answer:
5662
answer = 'y'
5763
answer = answer.lower()[0]

0 commit comments

Comments
 (0)