-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
73 lines (70 loc) · 2.71 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
<!DOCTYPE html>
<html>
<head>
<title>Simple Okta AuthJS</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
body {
margin-left: auto;
margin-right: auto;
max-width: 40em;
width: 88%;
}
</style>
</head>
<body>
<h1>Simple Okta AuthJS Example</h1>
<p>
If you using Chrome. Right click and select "Inspect" and navigate to Console tab to see the output.
</p>
<script src="https://global.oktacdn.com/okta-auth-js/5.2.1/okta-auth-js.min.js" type="text/javascript"></script>
<script>
// Bootstrap the AuthJS Client
const authClient = new OktaAuth({
// Org URL
url: 'https://{OKTA_ORG_URL}',
// OpenID Connect APP Client ID
clientId: '{OKTA_OIDC_CLIENT_ID}',
// Trusted Origin Redirect URI
redirectUri: 'http://localhost:8080/login/callback',
// Issuer
issuer: 'https://{OKTA_ORG_URL}/oauth2/default',
});
if (authClient.isLoginRedirect()) {
// Parse token from redirect url
authClient.token.parseFromUrl()
.then(data => {
const { idToken } = data.tokens;
console.log(`Hi ${idToken.claims.email}!`);
// Store parsed token in Token Manager
authClient.tokenManager.add('idToken', idToken);
console.log(idToken);
});
} else {
// Attempt to retrieve ID Token from Token Manager
authClient.tokenManager.get('idToken')
.then(idToken => {
console.log(idToken);
if (idToken) {
console.log(`Hi ${idToken.claims.email}!`);
} else {
var username = prompt('What is your username?');
var password = prompt('What is your password?');
authClient.signInWithCredentials({
username,
password,
})
.then(transaction => {
if (transaction.status === 'SUCCESS') {
authClient.token.getWithRedirect({
sessionToken: transaction.sessionToken,
responseType: 'id_token',
});
}
});
}
});
}
</script>
</body>
</html>