-
Notifications
You must be signed in to change notification settings - Fork 38
/
oktaAuth2.html
40 lines (39 loc) · 1.25 KB
/
oktaAuth2.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
<!doctype html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Sign in</title>
<script src="https://ok1static.oktacdn.com/assets/js/sdk/okta-auth-js/2.9.0/okta-auth-js.min.js"></script>
</head>
<body>
<form id=form>
Username <input id=username><br>
Password <input id=password type=password><br>
<input value="Sign In" type=submit>
</form>
<script>
// see https://github.com/okta/okta-auth-js
const config = {
issuer: 'https://dev-287042.okta.com/oauth2/default',
clientId: '0oa1wrcgeqgrLZBhm357'
};
form.onsubmit = function () {
const authClient = new OktaAuth(config);
authClient.signIn({username: username.value, password: password.value})
.then(transaction => {
console.log(transaction.sessionToken);
authClient.token.getWithoutPrompt({
responseType: 'token', // or array of types [code, token, and id_token]
sessionToken: transaction.sessionToken // optional if the user has an existing Okta session
})
.then(token => {
console.log(token); // TODO: Do something with token.
})
.catch(err => console.log(err));
})
.fail(err => console.log(err));
return false; // Cancel form submit.
};
</script>
</body>
</html>