@webex/plugin-authorization-browser-first-party 2.59.3-next.1 → 2.59.4-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/config.js CHANGED
@@ -1,38 +1,38 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- export default {
6
- credentials: {
7
- /**
8
- * Controls whether {@link Authorization#initiateLogin()} requests a token
9
- * or an auth code. Anything other than 'confidential' will be treated as
10
- * 'public'
11
- * @private
12
- * @type {string}
13
- */
14
- clientType: 'public',
15
-
16
- refreshCallback(webex, token) {
17
- /* eslint-disable camelcase */
18
- return webex
19
- .request({
20
- method: 'POST',
21
- uri: token.config.tokenUrl,
22
- form: {
23
- grant_type: 'refresh_token',
24
- redirect_uri: token.config.redirect_uri,
25
- refresh_token: token.refresh_token,
26
- },
27
- auth: {
28
- user: token.config.client_id,
29
- pass: token.config.client_secret,
30
- sendImmediately: true,
31
- },
32
- shouldRefreshAccessToken: false,
33
- })
34
- .then((res) => res.body);
35
- /* eslint-enable camelcase */
36
- },
37
- },
38
- };
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ export default {
6
+ credentials: {
7
+ /**
8
+ * Controls whether {@link Authorization#initiateLogin()} requests a token
9
+ * or an auth code. Anything other than 'confidential' will be treated as
10
+ * 'public'
11
+ * @private
12
+ * @type {string}
13
+ */
14
+ clientType: 'public',
15
+
16
+ refreshCallback(webex, token) {
17
+ /* eslint-disable camelcase */
18
+ return webex
19
+ .request({
20
+ method: 'POST',
21
+ uri: token.config.tokenUrl,
22
+ form: {
23
+ grant_type: 'refresh_token',
24
+ redirect_uri: token.config.redirect_uri,
25
+ refresh_token: token.refresh_token,
26
+ },
27
+ auth: {
28
+ user: token.config.client_id,
29
+ pass: token.config.client_secret,
30
+ sendImmediately: true,
31
+ },
32
+ shouldRefreshAccessToken: false,
33
+ })
34
+ .then((res) => res.body);
35
+ /* eslint-enable camelcase */
36
+ },
37
+ },
38
+ };
package/src/index.js CHANGED
@@ -1,18 +1,18 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- import {registerPlugin} from '@webex/webex-core';
6
-
7
- import Authorization from './authorization';
8
- import config from './config';
9
-
10
- const proxies = ['isAuthorizing', 'isAuthenticating'];
11
-
12
- registerPlugin('authorization', Authorization, {
13
- config,
14
- proxies,
15
- });
16
-
17
- export {default} from './authorization';
18
- export {default as config} from './config';
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ import {registerPlugin} from '@webex/webex-core';
6
+
7
+ import Authorization from './authorization';
8
+ import config from './config';
9
+
10
+ const proxies = ['isAuthorizing', 'isAuthenticating'];
11
+
12
+ registerPlugin('authorization', Authorization, {
13
+ config,
14
+ proxies,
15
+ });
16
+
17
+ export {default} from './authorization';
18
+ export {default as config} from './config';
@@ -1,60 +1,60 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- /* eslint-env browser */
6
-
7
- import '@babel/polyfill';
8
- import '@webex/plugin-authorization-browser-first-party';
9
- import StorageAdapterLocalStorage from '@webex/storage-adapter-local-storage';
10
- import WebexCore from '@webex/webex-core';
11
-
12
- import pkg from '../../../package';
13
-
14
- const webex = (window.webex = new WebexCore({
15
- config: {
16
- storage: {
17
- boundedAdapter: new StorageAdapterLocalStorage('webex'),
18
- },
19
- },
20
- }));
21
-
22
- webex.once('ready', () => {
23
- if (webex.canAuthorize) {
24
- document.getElementById('access-token').innerHTML = webex.credentials.supertoken.access_token;
25
- document.getElementById('refresh-token').innerHTML = webex.credentials.supertoken.refresh_token;
26
-
27
- webex
28
- .request({
29
- uri: 'https://locus-a.wbx2.com/locus/api/v1/ping',
30
- })
31
- .then(() => {
32
- document.getElementById('ping-complete').innerHTML = 'success';
33
- });
34
- }
35
- });
36
-
37
- // ready class implies js has loaded and selenium can start doing stuff
38
- document.body.classList.add('ready');
39
-
40
- document.getElementById('initiate-authorization-code-grant').addEventListener('click', () => {
41
- webex.config.credentials.clientType = 'confidential';
42
- webex.authorization.initiateLogin({
43
- state: {
44
- exchange: false,
45
- name: pkg.name,
46
- },
47
- });
48
- });
49
-
50
- document.getElementById('token-refresh').addEventListener('click', () => {
51
- document.getElementById('access-token').innerHTML = '';
52
- webex.refresh({force: true}).then(() => {
53
- document.getElementById('access-token').innerHTML = webex.credentials.supertoken.access_token;
54
- document.getElementById('refresh-token').innerHTML = webex.credentials.supertoken.refresh_token;
55
- });
56
- });
57
-
58
- document.getElementById('logout').addEventListener('click', () => {
59
- webex.logout();
60
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ /* eslint-env browser */
6
+
7
+ import '@babel/polyfill';
8
+ import '@webex/plugin-authorization-browser-first-party';
9
+ import StorageAdapterLocalStorage from '@webex/storage-adapter-local-storage';
10
+ import WebexCore from '@webex/webex-core';
11
+
12
+ import pkg from '../../../package';
13
+
14
+ const webex = (window.webex = new WebexCore({
15
+ config: {
16
+ storage: {
17
+ boundedAdapter: new StorageAdapterLocalStorage('webex'),
18
+ },
19
+ },
20
+ }));
21
+
22
+ webex.once('ready', () => {
23
+ if (webex.canAuthorize) {
24
+ document.getElementById('access-token').innerHTML = webex.credentials.supertoken.access_token;
25
+ document.getElementById('refresh-token').innerHTML = webex.credentials.supertoken.refresh_token;
26
+
27
+ webex
28
+ .request({
29
+ uri: 'https://locus-a.wbx2.com/locus/api/v1/ping',
30
+ })
31
+ .then(() => {
32
+ document.getElementById('ping-complete').innerHTML = 'success';
33
+ });
34
+ }
35
+ });
36
+
37
+ // ready class implies js has loaded and selenium can start doing stuff
38
+ document.body.classList.add('ready');
39
+
40
+ document.getElementById('initiate-authorization-code-grant').addEventListener('click', () => {
41
+ webex.config.credentials.clientType = 'confidential';
42
+ webex.authorization.initiateLogin({
43
+ state: {
44
+ exchange: false,
45
+ name: pkg.name,
46
+ },
47
+ });
48
+ });
49
+
50
+ document.getElementById('token-refresh').addEventListener('click', () => {
51
+ document.getElementById('access-token').innerHTML = '';
52
+ webex.refresh({force: true}).then(() => {
53
+ document.getElementById('access-token').innerHTML = webex.credentials.supertoken.access_token;
54
+ document.getElementById('refresh-token').innerHTML = webex.credentials.supertoken.refresh_token;
55
+ });
56
+ });
57
+
58
+ document.getElementById('logout').addEventListener('click', () => {
59
+ webex.logout();
60
+ });
@@ -1,24 +1,24 @@
1
- <!DOCTYPE html>
2
- <html>
3
- <head>
4
- <title>Authorization Automation Test</title>
5
- </head>
6
- <body class="authorization-automation-test">
7
- <button title="Login with Authorization Code Grant" id="initiate-authorization-code-grant">
8
- Login with Authorization Code Grant
9
- </button>
10
- <button title="Refresh Access Token" id="token-refresh">Refresh Access Token</button>
11
-
12
- <h1>Access Token</h1>
13
- <div id="access-token"></div>
14
- <h1>Refresh Token</h1>
15
- <div id="refresh-token"></div>
16
-
17
- <h1>Pinging WDM</h1>
18
- <div id="ping-complete"></div>
19
-
20
- <button title="Logout" id="logout">Logout</button>
21
-
22
- <script src="app.js"></script>
23
- </body>
24
- </html>
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Authorization Automation Test</title>
5
+ </head>
6
+ <body class="authorization-automation-test">
7
+ <button title="Login with Authorization Code Grant" id="initiate-authorization-code-grant">
8
+ Login with Authorization Code Grant
9
+ </button>
10
+ <button title="Refresh Access Token" id="token-refresh">Refresh Access Token</button>
11
+
12
+ <h1>Access Token</h1>
13
+ <div id="access-token"></div>
14
+ <h1>Refresh Token</h1>
15
+ <div id="refresh-token"></div>
16
+
17
+ <h1>Pinging WDM</h1>
18
+ <div id="ping-complete"></div>
19
+
20
+ <button title="Logout" id="logout">Logout</button>
21
+
22
+ <script src="app.js"></script>
23
+ </body>
24
+ </html>
@@ -1,151 +1,151 @@
1
- /*!
2
- * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
- */
4
-
5
- /* eslint-disable indent */
6
-
7
- import {assert} from '@webex/test-helper-chai';
8
- import {createBrowser} from '@webex/test-helper-automation';
9
- import testUsers from '@webex/test-helper-test-users';
10
-
11
- import pkg from '../../../package';
12
-
13
- const redirectUri = process.env.WEBEX_REDIRECT_URI || process.env.REDIRECT_URI;
14
-
15
- // Run the tests with and without Federation enabled,
16
- // for test users in EU (Federation) and US
17
- // Also try US user with Federation enabled
18
- const runs = [
19
- {
20
- it: 'with EU user with Federation enabled',
21
- EUUser: true,
22
- attrs: {config: {credentials: {federation: true}}},
23
- },
24
- {it: 'with US user without Federation enabled', EUUser: false, attrs: {}},
25
- {
26
- it: 'with US user with Federation enabled',
27
- EUUser: false,
28
- attrs: {config: {credentials: {federation: true}}},
29
- },
30
- ];
31
-
32
- runs.forEach((run) => {
33
- describe(`plugin-authorization-browser-first-party ${run.it}`, function () {
34
- this.timeout(120000);
35
-
36
- describe('Authorization', () => {
37
- describe.skip('Authorization Code Grant', () => {
38
- let browser, user;
39
-
40
- const testUserParm = {count: 1};
41
-
42
- if (run.EUUser) {
43
- testUserParm.config = {orgId: process.env.EU_PRIMARY_ORG_ID};
44
- }
45
-
46
- before(() =>
47
- testUsers.create(testUserParm).then((users) => {
48
- user = users[0];
49
- })
50
- );
51
-
52
- before(() =>
53
- createBrowser(pkg).then((b) => {
54
- browser = b;
55
- })
56
- );
57
-
58
- after(() => browser && browser.printLogs());
59
-
60
- after(
61
- () =>
62
- browser &&
63
- browser.quit().catch((reason) => {
64
- console.warn(reason);
65
- })
66
- );
67
-
68
- it('authorizes a user', () =>
69
- browser
70
- .get(`${redirectUri}/${pkg.name}`)
71
- .waitForElementByClassName('ready')
72
- .title()
73
- .should.eventually.become('Authorization Automation Test')
74
- .waitForElementByCssSelector('[title="Login with Authorization Code Grant"]')
75
- .click()
76
- .login(user)
77
- .waitForElementByClassName('authorization-automation-test')
78
- .waitForElementById('refresh-token')
79
- .text()
80
- .should.eventually.not.be.empty.waitForElementByCssSelector(
81
- '#ping-complete:not(:empty)'
82
- )
83
- .text()
84
- .should.eventually.become('success'));
85
-
86
- it('is still logged in after reloading the page', () =>
87
- browser
88
- .waitForElementById('access-token')
89
- .text()
90
- .should.eventually.not.be.empty.get(`${redirectUri}/${pkg.name}`)
91
- .sleep(500)
92
- .waitForElementById('access-token')
93
- .text().should.eventually.not.be.empty);
94
-
95
- it("refreshes the user's access token", () => {
96
- let accessToken = '';
97
-
98
- return (
99
- browser
100
- .waitForElementByCssSelector('#access-token:not(:empty)')
101
- .text()
102
- .then((text) => {
103
- accessToken = text;
104
- assert.isString(accessToken);
105
- assert.isAbove(accessToken.length, 0);
106
-
107
- return browser;
108
- })
109
- .waitForElementByCssSelector('[title="Refresh Access Token"]')
110
- .click()
111
- // Not thrilled by a sleep, but we just need to give the button click
112
- // enough time to clear the #access-token box
113
- .sleep(500)
114
- .waitForElementByCssSelector('#access-token:not(:empty)')
115
- .text()
116
- .then((text) => {
117
- assert.isString(text);
118
- assert.isAbove(text.length, 0);
119
- assert.notEqual(text, accessToken);
120
-
121
- return browser;
122
- })
123
- );
124
- });
125
-
126
- it('logs out a user', () =>
127
- browser
128
- .title()
129
- .should.eventually.become('Authorization Automation Test')
130
- .waitForElementByCssSelector('[title="Logout"]')
131
- .click()
132
- // We need to revoke three tokens before the window.location assignment.
133
- // So far, I haven't found any ques to wait for, so sleep seems to be
134
- // the only option.
135
- .sleep(3000)
136
- .title()
137
- .should.eventually.become('Redirect Dispatcher')
138
- .get(`${redirectUri}/${pkg.name}`)
139
- .title()
140
- .should.eventually.become('Authorization Automation Test')
141
- .waitForElementById('access-token')
142
- .text()
143
- .should.eventually.be.empty.waitForElementByCssSelector(
144
- '[title="Login with Authorization Code Grant"]'
145
- )
146
- .click()
147
- .waitForElementById('IDToken1'));
148
- });
149
- });
150
- });
151
- });
1
+ /*!
2
+ * Copyright (c) 2015-2020 Cisco Systems, Inc. See LICENSE file.
3
+ */
4
+
5
+ /* eslint-disable indent */
6
+
7
+ import {assert} from '@webex/test-helper-chai';
8
+ import {createBrowser} from '@webex/test-helper-automation';
9
+ import testUsers from '@webex/test-helper-test-users';
10
+
11
+ import pkg from '../../../package';
12
+
13
+ const redirectUri = process.env.WEBEX_REDIRECT_URI || process.env.REDIRECT_URI;
14
+
15
+ // Run the tests with and without Federation enabled,
16
+ // for test users in EU (Federation) and US
17
+ // Also try US user with Federation enabled
18
+ const runs = [
19
+ {
20
+ it: 'with EU user with Federation enabled',
21
+ EUUser: true,
22
+ attrs: {config: {credentials: {federation: true}}},
23
+ },
24
+ {it: 'with US user without Federation enabled', EUUser: false, attrs: {}},
25
+ {
26
+ it: 'with US user with Federation enabled',
27
+ EUUser: false,
28
+ attrs: {config: {credentials: {federation: true}}},
29
+ },
30
+ ];
31
+
32
+ runs.forEach((run) => {
33
+ describe(`plugin-authorization-browser-first-party ${run.it}`, function () {
34
+ this.timeout(120000);
35
+
36
+ describe('Authorization', () => {
37
+ describe.skip('Authorization Code Grant', () => {
38
+ let browser, user;
39
+
40
+ const testUserParm = {count: 1};
41
+
42
+ if (run.EUUser) {
43
+ testUserParm.config = {orgId: process.env.EU_PRIMARY_ORG_ID};
44
+ }
45
+
46
+ before(() =>
47
+ testUsers.create(testUserParm).then((users) => {
48
+ user = users[0];
49
+ })
50
+ );
51
+
52
+ before(() =>
53
+ createBrowser(pkg).then((b) => {
54
+ browser = b;
55
+ })
56
+ );
57
+
58
+ after(() => browser && browser.printLogs());
59
+
60
+ after(
61
+ () =>
62
+ browser &&
63
+ browser.quit().catch((reason) => {
64
+ console.warn(reason);
65
+ })
66
+ );
67
+
68
+ it('authorizes a user', () =>
69
+ browser
70
+ .get(`${redirectUri}/${pkg.name}`)
71
+ .waitForElementByClassName('ready')
72
+ .title()
73
+ .should.eventually.become('Authorization Automation Test')
74
+ .waitForElementByCssSelector('[title="Login with Authorization Code Grant"]')
75
+ .click()
76
+ .login(user)
77
+ .waitForElementByClassName('authorization-automation-test')
78
+ .waitForElementById('refresh-token')
79
+ .text()
80
+ .should.eventually.not.be.empty.waitForElementByCssSelector(
81
+ '#ping-complete:not(:empty)'
82
+ )
83
+ .text()
84
+ .should.eventually.become('success'));
85
+
86
+ it('is still logged in after reloading the page', () =>
87
+ browser
88
+ .waitForElementById('access-token')
89
+ .text()
90
+ .should.eventually.not.be.empty.get(`${redirectUri}/${pkg.name}`)
91
+ .sleep(500)
92
+ .waitForElementById('access-token')
93
+ .text().should.eventually.not.be.empty);
94
+
95
+ it("refreshes the user's access token", () => {
96
+ let accessToken = '';
97
+
98
+ return (
99
+ browser
100
+ .waitForElementByCssSelector('#access-token:not(:empty)')
101
+ .text()
102
+ .then((text) => {
103
+ accessToken = text;
104
+ assert.isString(accessToken);
105
+ assert.isAbove(accessToken.length, 0);
106
+
107
+ return browser;
108
+ })
109
+ .waitForElementByCssSelector('[title="Refresh Access Token"]')
110
+ .click()
111
+ // Not thrilled by a sleep, but we just need to give the button click
112
+ // enough time to clear the #access-token box
113
+ .sleep(500)
114
+ .waitForElementByCssSelector('#access-token:not(:empty)')
115
+ .text()
116
+ .then((text) => {
117
+ assert.isString(text);
118
+ assert.isAbove(text.length, 0);
119
+ assert.notEqual(text, accessToken);
120
+
121
+ return browser;
122
+ })
123
+ );
124
+ });
125
+
126
+ it('logs out a user', () =>
127
+ browser
128
+ .title()
129
+ .should.eventually.become('Authorization Automation Test')
130
+ .waitForElementByCssSelector('[title="Logout"]')
131
+ .click()
132
+ // We need to revoke three tokens before the window.location assignment.
133
+ // So far, I haven't found any ques to wait for, so sleep seems to be
134
+ // the only option.
135
+ .sleep(3000)
136
+ .title()
137
+ .should.eventually.become('Redirect Dispatcher')
138
+ .get(`${redirectUri}/${pkg.name}`)
139
+ .title()
140
+ .should.eventually.become('Authorization Automation Test')
141
+ .waitForElementById('access-token')
142
+ .text()
143
+ .should.eventually.be.empty.waitForElementByCssSelector(
144
+ '[title="Login with Authorization Code Grant"]'
145
+ )
146
+ .click()
147
+ .waitForElementById('IDToken1'));
148
+ });
149
+ });
150
+ });
151
+ });