-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.html
180 lines (142 loc) · 6.49 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
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
171
172
173
174
175
176
177
178
179
180
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<title>Cognito Login Test</title>
<!-- Bootstrap core CSS -->
<link href="bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="ie10-viewport-bug-workaround.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="signin.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
<script type="text/javascript" src="aws-sdk-2.77.0.js"></script>
<script type="text/javascript" src="aws-cognito-sdk.js"></script>
<script type="text/javascript" src="amazon-cognito-identity.js"></script>
<script type="text/javascript" src="vue.js"></script>
</head>
<body>
<script>
</script>
<div class="container">
<div id="cognito-info" class="form-signin">
<label for="UserPoolID" >User Pool Id</label>
<input v-model="UserPoolID" type="text" id="UserPoolID" class="form-control" placeholder="us-east-2_dtMDOdMiU" required autofocus>
<label for="ClientId" >App Client Id</label>
<input v-model="ClientId" type="text" id="ClientId" class="form-control" placeholder="14e0a0cypfl2cna4hccaj07ohr" required>
</div>
<div id="messages" class="form-signin">
<span>Last Message: {{message}} </span>
</div>
<form id="sign-in-form" v-show="show" class="form-signin">
<h2 class="form-signin-heading">Please sign in</h2>
<label for="userName" class="sr-only">Username</label>
<input v-model="Username" type="text" id="userName" class="form-control" placeholder="Username" required autofocus>
<label for="inputPassword" class="sr-only">Password</label>
<input v-model="Password" type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<button v-on:click="login" class="btn btn-lg btn-primary btn-block" type="submit">Sign in</button>
</form>
<form id="update-password-form" v-show="show" class="form-signin">
<h2 class="form-signin-heading">Change Password</h2>
<label for="inputPassword" class="sr-only">New Password</label>
<input v-model="Password" type="password" id="inputPassword" class="form-control" placeholder="Password" required>
<button v-on:click="change" class="btn btn-lg btn-primary btn-block" type="submit">Update</button>
</form>
</div>
<script type="text/javascript">
var messages = new Vue({
el: "#messages",
data: {
message: ''
}
})
var cognitoInfo = new Vue({
el: "#cognito-info",
data: {
UserPoolID: '',
ClientId: ''
}
});
var changeWrapper;
var updatePassword = new Vue({
el: "#update-password-form",
data: {
Password: '',
show: false
},
methods: {
change: function(event) {
event.preventDefault();
changeWrapper(this.Password);
}
}
});
var authenticationDetails,
userPool,
cognitoUser;
var app = new Vue({
el: '#sign-in-form',
data: {
Username: '',
Password: '',
show: true
},
methods: {
login: function (event) {
event.preventDefault();
authenticationDetails = new AWSCognito.CognitoIdentityServiceProvider.AuthenticationDetails({
"Username": this.Username,
"Password": this.Password
});
userPool = new AWSCognito.CognitoIdentityServiceProvider.CognitoUserPool({
"UserPoolId": cognitoInfo.UserPoolID,
"ClientId": cognitoInfo.ClientId
});
var userData = {
Username : this.Username,
Pool : userPool
};
cognitoUser = new AWSCognito.CognitoIdentityServiceProvider.CognitoUser(userData);
cognitoUser.authenticateUser(authenticationDetails, {
onSuccess: function (result) {
console.log('access token + ' + result.getAccessToken().getJwtToken());
/*Use the idToken for Logins Map when Federating User Pools with Cognito Identity or when passing through an Authorization Header to an API Gateway Authorizer*/
console.log('idToken + ' + result.idToken.jwtToken);
messages.message = "Welcome! You've successfully authenticated! :)";
app.show = false;
},
onFailure: function(err) {
messages.message = err.message;
},
newPasswordRequired: function(userAttributes, requiredAttributes) {
// User was signed up by an admin and must provide new
// password and required attributes, if any, to complete
// authentication.
// the api doesn't accept this field back
updatePassword.show = true;
app.show = false;
delete userAttributes.email_verified;
delete userAttributes.phone_number_verified;
console.log(userAttributes, requiredAttributes);
// Get these details and call
var that = this;
changeWrapper = function(newPassword) {
cognitoUser.completeNewPasswordChallenge(newPassword, userAttributes, that);
}
}
});
}
}
});
</script>
</body>
</html>