-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
61 lines (50 loc) · 1.2 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">
<title>TestApi</title>
<style>
input {
margin-bottom: 5px;
display: block;
}
</style>
</head>
<body>
<form method="POST">
<input type="email" id="email" placeholder="Email" />
<input type="password" id="password" placeholder="Contraseña" />
<input type="submit" id="login" value="Ingresar" />
</form>
<ul></ul>
<script>
(function () {
'use strict';
const clientId = 1;
const clientSecret = 'Your-Client-Secret';
const grantType = 'password';
let login = document.getElementById('login');
login.addEventListener('click', e => {
e.preventDefault();
fetch('http://localhost:8080/oauth/token', {
method: 'POST',
body: JSON.stringify({
client_id: clientId,
client_secret: clientSecret,
grant_type: grantType,
username: document.getElementById('email').value,
password: document.getElementById('password').value
}),
headers: { 'Content-Type': 'application/json' },
})
.then(response => {
return response.json()
})
.then(data => {
localStorage.setItem('token', data.access_token)
})
});
})();
</script>
</body>
</html>