blob: bc88357f1e570717f76910191985071c0ded2837 (
plain)
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>c0</title>
<script src="https://unpkg.com/vue@3"></script>
</head>
<body>
<p><%= .Message %></p>
<%= if .IsLoggedIn %>
<div id="app" data-token="<%=.Token.AccessToken%>">
<p>{{message}}</p>
<p>
<button type="button" @click="fetchPublicData">Public</button>
<button type="button" @click="fetchPrivateData">Private</button>
<button type="button" @click="fetchPrivateScopedData">Private Scoped</button>
<a href="/logout">Logout</a>
</p>
<h1>Access Token</h1>
<textarea rows="4" cols="200" disabled=disabled><%= .Token.AccessToken %></textarea>
<%= range $key, $value := .AccessTokenClaims %>
<li><strong><%= $key %></strong>: <%= $value %></li>
<%= end %>
<h1>Id Token</h1>
<ul>
<li>issuer: <%=.IdToken.Issuer%></li>
<li>audience: <%=.IdToken.Audience%></li>
<li>subject: <%=.IdToken.Subject%></li>
<li>expire: <%=.IdToken.Expiry%></li>
<li>issued at: <%=.IdToken.IssuedAt%></li>
<li>nonce: <%=.IdToken.Nonce%></li>
</ul>
<textarea rows="4" cols="200" disabled=disabled><%= .IdToken %></textarea>
<h1>Id Token Claims</h1>
<%= range $key, $value := .Profile %>
<li><strong><%= $key %></strong>: <%= $value %></li>
<%= end %>
<textarea rows="4" cols="200" disabled=disabled><%=.IdTokenRaw%></textarea>
</div>
<script>
const { createApp } = Vue;
createApp({
data() {
return {
message: "hello vue!"
}
},
methods: {
accessToken() {
let element = document.querySelector('#app');
return `Bearer ${element.dataset['token']}`;
},
fetchPublicData() {
fetch("http://localhost:3000/api/public")
.then((x) => x.json())
.then((x) => this.message = x.message)
.catch((error) => this.message = error.message)
},
fetchPrivateData() {
let headers = new Headers();
headers.append("Authorization", this.accessToken())
fetch("http://localhost:3000/api/private", { headers: headers })
.then((x) => x.json())
.then((x) => this.message = x.message)
.catch((error) => this.message = error.message)
},
fetchPrivateScopedData() {
let headers = new Headers();
headers.append("Authorization", this.accessToken())
fetch("http://localhost:3000/api/private-scoped", { headers: headers })
.then((x) => x.json())
.then((x) => this.message = x.message)
.catch((error) => this.message = error.message)
}
}
}).mount('#app')
</script>
<%= else %>
<a href="/login">Login</a>
<%= end %>
</body>
</html>
|