-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
61 lines (58 loc) · 2.15 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="google-signin-scope" content="profile email">
<meta name="google-signin-client_id" content="370606383019-jn3m29h3sq463rr42i3bv53v34vk4ups.apps.googleusercontent.com">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="assets/site.css">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>NATS Websocket Demo</title>
</head>
<body class="black">
<div class="jumbotron jumbotron-fluid black d-flex justify-content-center">
<img src="assets/large-logo.png" id="logo" class="img-fluid" alt="logo"/>
<h1 class="mx-auto">Websocket Demo</h1>
<p class="lead">Welcome to NATS running natively in the browser!</p>
<p class="lead text-white"><a href="https://github.com/nats-io/nats.ws">https://github.com/nats-io/nats.ws</a></p>
<div id="google-signing-button"></div>
</div>
<script>
function renderButton () {
gapi.signin2.render('google-signing-button', {
scope: 'profile email',
width: 240,
height: 50,
longtitle: true,
theme: 'dark',
onsuccess: onSuccess,
onfailure: onFailure
})
}
function onSuccess (gu) {
const id_token = gu.getAuthResponse().id_token
const xhr = new XMLHttpRequest()
xhr.open('POST', 'https://authdemo.nats-demo.info/api/token')
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded')
xhr.onload = () => {
if (xhr.status != 200) {
console.log(xhr.statusText)
alert('error authenticating - check the console')
return
}
location.href = '/app.html'
}
xhr.onerror = (err) => {
alert('request failed ' + err)
}
xhr.send('token=' + id_token)
}
function onFailure (error) {
console.log(error)
alert('Unable to log in - check the console')
}
</script>
<script src="https://apis.google.com/js/platform.js?onload=renderButton" async defer></script>
</body>
</html>