-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
144 lines (129 loc) · 4.96 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
<!DOCTYPE html>
<html>
<body>
<h1>Hello World</h1>
<p>I'm hosted with GitHub Pages.</p>
<p>and the journey begins</p>
</body>
<button id="logout" >Logout</button>
<script src="https://global.oktacdn.com/okta-auth-js/5.2.2/okta-auth-js.min.js" type="text/javascript"></script>
<script type="text/javascript" charset="utf-8">
(function (g, e, n, es) {
g['_genesysJs'] = e;
g[e] = g[e] || function () {
(g[e].q = g[e].q || []).push(arguments);
};
g[e].t = 1 * new Date();
g[e].c = es;
var ys = document.createElement('script');
ys.async = 1;
ys.src = n;
ys.charset = 'utf-8';
document.head.appendChild(ys);
})(window, 'Genesys', 'https://apps.mypurecloud.com.au/genesys-bootstrap/genesys.min.js', {
environment: 'prod-apse2',
deploymentId: 'deploymentId', //put in deploymentId
debug:true
});
let sNonce = '';
let authCode1 = '';
let sRedirectURL = '';
const currentURL = window.location.href;
if (currentURL.indexOf('code') <= -1) {
sRedirectURL = window.location.href;
} else {
// Retrieve and set redirectURI from session storage if available
let sOktaTransactionStorage = window.sessionStorage.getItem("okta-transaction-storage");
if (sOktaTransactionStorage) {
try {
const oStorage1 = JSON.parse(sOktaTransactionStorage);
if (oStorage1 && oStorage1.redirectUri) {
sRedirectURL = oStorage1.redirectUri || '';
}
} catch (error) {
console.error("Error parsing sessionStorage:", error);
}
}
}
console.log('sRedirectURL: ' + sRedirectURL);
//define okta config
const oktaConfig = {
redirectUri: sRedirectURL,
postLogoutRedirectUri: sRedirectURL,
clientId: 'clientId', //put in clientId
issuer: 'https://simply-energy-int.okta.com/oauth2/default/',
scopes: ['openid', 'email', 'profile', 'offline_access'],
pkce: false,
responseType: 'code',
maxAge : 86400
};
const authClient = new OktaAuth(oktaConfig);
// Initialize the Okta auth client with the config options
Genesys('registerPlugin', 'AuthProvider', (AuthProvider) => {
if (currentURL.indexOf('code') <= -1) {
authClient.signInWithRedirect({
originalUri: sRedirectURL,
...oktaConfig
});
} else {
// Retrieve and set nonce from session storage if available
let sOktaTransactionStorage = window.sessionStorage.getItem("okta-transaction-storage");
if (sOktaTransactionStorage) {
try {
const oStorage = JSON.parse(sOktaTransactionStorage);
if (oStorage && oStorage.nonce) {
sNonce = oStorage.nonce || '';
console.log('nonce: ' + sNonce);
}
} catch (error) {
console.error("Error parsing sessionStorage:", error);
}
}
}
// Get the authorization response from the query string
const urlParams = new URLSearchParams(window.location.search);
authCode1 = urlParams.has('code') ? urlParams.get('code') : '';
console.log('authcode: ' + authCode1);
// Register AuthProvider commands and subscriptions
AuthProvider.registerCommand('getAuthCode', (e) => {
e.resolve({
authCode: authCode1,
redirectUri: sRedirectURL,
nonce: sNonce,
maxAge: 86400
});
});
AuthProvider.subscribe('Auth.ready', (res) => {
console.log('AUTH READY');
console.log(res);
});
AuthProvider.subscribe('Auth.authenticated', (res) => {
const { message } = error.data || {};
console.log('Log authenticated');
console.log(res);
});
AuthProvider.registerCommand('reAuthenticate', (e) => {
e.resolve();
});
AuthProvider.subscribe('Auth.error', (error) => {
const { message } = error.data || {};
// 'message' here is provided by our API and its always expected to be in string. Any security scan results are false postive in this case.
console.log("Auth Error", message);
// LocalStorage usage is must for this product
localStorage.setItem('authFetching', false); // eslint-disable-line
});
AuthProvider.subscribe('Auth.authError', (error) => {
// 'message' here is provided by our API and its always expected to be in string. Any security scan results are false postive in this case.
console.log("Auth Error", error);
});
const AuthLogoutBtn = document.getElementById('logout');
AuthLogoutBtn.onclick = function () {
AuthProvider.command('Auth.logout')
.finally(() => {
if (authClient) authClient.signOut();
});
};
AuthProvider.ready();
});
</script>
</html>