-
Notifications
You must be signed in to change notification settings - Fork 18
/
utils.js
114 lines (108 loc) · 3.2 KB
/
utils.js
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
/**
* Displays a log of information onto the page
* @param {String} type Label of the information about to be logged
* @param {Object} data Object that can be JSON stringified
*/
function log(type, data) {
var ul = document.getElementById("console");
var li = document.createElement("li");
var header = document.createElement("p");
var headerMessage = document.createTextNode(
`${new Date().toJSON()}: ${type}`
);
header.appendChild(headerMessage);
li.appendChild(header);
var code = document.createElement("pre");
var payload = document.createTextNode(`${JSON.stringify(data, "\n", 2)}`);
code.appendChild(payload);
li.appendChild(code);
ul.prepend(li);
}
/**
* Logs the app object from `new window.Webex.Application();`
*/
function handleDisplayAppInfo() {
log("Webex Embedded App Application Object", app);
}
/**
* Calls and logs the user data from `app.context.getUser()`
*/
function handleGetUser() {
app.context
.getUser()
.then((u) => {
log("getUser()", u);
})
.catch((error) => {
log(
"getUser() promise failed with error",
Webex.Application.ErrorCodes[error]
);
});
}
/**
* Calls and logs the meeting data from `app.context.getMeeting()`
*/
function handleGetMeeting() {
app.context
.getMeeting()
.then((m) => {
log("getMeeting()", m);
})
.catch((error) => {
log(
"getMeeting() promise failed with error",
Webex.Application.ErrorCodes[error]
);
});
}
/**
* Calls and logs the space data from `app.context.getSpace()`
*/
function handleGetSpace() {
app.context
.getSpace()
.then((s) => {
log("getSpace()", s);
})
.catch((error) => {
log(
"getSpace() promise failed with error",
Webex.Application.ErrorCodes[error]
);
});
}
/**
* Initiates the System Browser OAuth flow for SSO
*/
function handleSystemBrowserOAuth() {
// System Browser OAuth Support is only for 1.5.0 SDK and above
log('app.isSdkSupported("1.5.0")', app.isSdkSupported("1.5.0"));
if (!app.isSdkSupported("1.5.0")) {
return;
}
// The redirect from your SSO flow needs to return to this Webex address
const webexAppRedirectUri =
"https://oauth-helper-prod.wbx2.com/helperservice/v1/callback";
// We are utiling mocklab to demonstrate an SSO Flow
// Be sure to add the SSO domain to your "valid domains" configuration
const SSOAuthUrl = `https://oauth.mocklab.io/oauth/authorize?response_type=code&redirect_uri=${webexAppRedirectUri}`;
log("Initiating SSO flow in system browser", true);
// Initiate SSO flow in system browser
app
.initiateSystemBrowserOAuth(SSOAuthUrl)
.then(function (response) {
// Promise fulfilled, get authorization code from JSON response
let authCode = response;
log("SSO flow got authorization code", authCode);
// Exchange authorization code for a token with ID provider.
// This part of the OAuth flow is the responsibility of the embedded app, for example:
// exchangeCodeForToken(authCode);
})
.catch(function (reason) {
console.error(
"initiateSystemBrowserOAuth() failed with reason=",
window.Webex.Application.ErrorCodes[reason]
);
});
}