-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
170 lines (133 loc) · 5.49 KB
/
index.php
File metadata and controls
170 lines (133 loc) · 5.49 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/css/bootstrap.min.css" integrity="sha384-WskhaSGFgHYWDcbwN70/dfYBj47jz9qbsMId/iRN3ewGhXQFZCSftd1LZCfmhktB" crossorigin="anonymous">
<title>JWT</title>
</head>
<body>
<div class="container p-5">
<div class="h1 text-center">JWT Made Simple</div>
<div class="py-5">
<img src="assets/images/how_jwt_works.png" alt="img-fluid">
</div>
<div class="h1 text-center my-4">See in action</div>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">Step No.</th>
<th scope="col">Client Side</th>
<th scope="col">Server Side Response</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>User Sign-in (using email/password)
<hr>
<form class="form-signin" id="frmLogin">
<label class="mb-2">Email address</label>
<input type="text" value="shishir.raven@gmail.com" name="email" id="inputEmail" class=" mb-2 form-control" placeholder="Email address" required autofocus>
<label for="inputPassword" class="mb-2" value="123456">Password</label>
<input name="password" type="password" id="inputPassword" class="mb-2 form-control" placeholder="Password" required>
<button class="btn btn-primary " type="submit">Send email/password to server </button>
<hr>
<div class="bg-light rounded p-3">
Hint <br>
Username : shishir.raven@gmail.com <br>
Password : 123456
</div>
</form>
</td>
<td>
Accept Username / password and check validity, If correct return JWT to the Client.
<hr>
RESULT from <b>token_issuer.php</b>
<div class="bg-warning rounded p-3" id="loginResult">⚠️ Fill the login form to see results here</div>
<hr>
You can verify the token here <a href="https://jwt.io/">jwt.io</a>
</td>
</tr>
<tr>
<th scope="row">2</th>
<td>
JWT
<input type="text" class="form-control" id="jwt">
<div class="btn btn-primary" id="btnGetResource">Send Request</div>
</td>
<td>
Get the data if a valid JWT is sent to the server in authentication header
<hr>
RESULT from <strong>get_request.php</strong>
<div class="bg-warning rounded p-3" id="requestResult">⚠️ Send Request to see results</div>
<hr>
</td>
</tr>
</tbody>
</table>
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script
src="https://code.jquery.com/jquery-3.3.1.min.js"
integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.1/js/bootstrap.min.js" integrity="sha384-smHYKdLADwkXOn1EmN1qk/HfnUcbVRZyYmZ4qpPea6sjB/pTJ0euyQp0Mk8ck+5T" crossorigin="anonymous"></script>
<script>
$(function(){
var store = store || {};
/*
* Sets the jwt to the store object
*/
store.setJWT = function(data){
this.JWT = data;
}
$("#btnGetResource").click(function(e){
e.preventDefault();
$.ajax({
url: 'get_request.php',
beforeSend: function(request){
request.setRequestHeader('Authorization', 'Bearer ' + $("#jwt").val());
},
type: 'GET',
success: function(data) {
// Decode and show the returned data nicely.
$("#requestResult").text(JSON.stringify(data));
},
error: function() {
$("#requestResult").text("❌ Error form Server");
}
});
});
/*
* Submit the login form via ajax
*/
$("#frmLogin").submit(function(e)
{
e.preventDefault();
$.ajax({
type: "POST",
dataType: "JSON",
url: 'token_issuer.php',
data: $("#frmLogin").serialize(),
success: function(data)
{
store.setJWT(data.jwt);
$("#loginResult").text(store.JWT);
$("#jwt").val(store.JWT);
},
fail: function()
{
$("#jwt").val("error");
$("#loginResult").text("Error");
}
});
});
});
</script>
</body>
</html>