@webex/plugin-authorization-browser 3.0.0-beta.9 → 3.0.0-beta.90

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/index.js CHANGED
@@ -8,14 +8,11 @@ import {registerPlugin} from '@webex/webex-core';
8
8
  import Authorization from './authorization';
9
9
  import config from './config';
10
10
 
11
- const proxies = [
12
- 'isAuthorizing',
13
- 'isAuthenticating'
14
- ];
11
+ const proxies = ['isAuthorizing', 'isAuthenticating'];
15
12
 
16
13
  registerPlugin('authorization', Authorization, {
17
14
  config,
18
- proxies
15
+ proxies,
19
16
  });
20
17
 
21
18
  export {default} from './authorization';
@@ -10,35 +10,37 @@ import WebexCore from '@webex/webex-core';
10
10
 
11
11
  import pkg from '../../../package';
12
12
 
13
- const webex = window.webex = new WebexCore({
13
+ const webex = (window.webex = new WebexCore({
14
14
  config: {
15
15
  credentials: {
16
16
  refreshCallback(webex, token) {
17
- return webex.request({
18
- method: 'POST',
19
- uri: '/refresh',
20
- body: {
21
- // eslint-disable-next-line camelcase
22
- refresh_token: token.refresh_token
23
- }
24
- })
17
+ return webex
18
+ .request({
19
+ method: 'POST',
20
+ uri: '/refresh',
21
+ body: {
22
+ // eslint-disable-next-line camelcase
23
+ refresh_token: token.refresh_token,
24
+ },
25
+ })
25
26
  .then((res) => res.body);
26
- }
27
+ },
27
28
  },
28
29
  storage: {
29
- boundedAdapter: new StorageAdapterLocalStorage('webex')
30
- }
31
- }
32
- });
30
+ boundedAdapter: new StorageAdapterLocalStorage('webex'),
31
+ },
32
+ },
33
+ }));
33
34
 
34
35
  webex.once('ready', () => {
35
36
  if (webex.canAuthorize) {
36
37
  document.getElementById('access-token').innerHTML = webex.credentials.supertoken.access_token;
37
38
  document.getElementById('refresh-token').innerHTML = webex.credentials.supertoken.refresh_token;
38
39
 
39
- webex.request({
40
- uri: 'https://locus-a.wbx2.com/locus/api/v1/ping'
41
- })
40
+ webex
41
+ .request({
42
+ uri: 'https://locus-a.wbx2.com/locus/api/v1/ping',
43
+ })
42
44
  .then(() => {
43
45
  document.getElementById('ping-complete').innerHTML = 'success';
44
46
  });
@@ -50,24 +52,23 @@ document.body.classList.add('ready');
50
52
 
51
53
  document.getElementById('initiate-implicit-grant').addEventListener('click', () => {
52
54
  webex.authorization.initiateLogin({
53
- state: {name: pkg.name}
55
+ state: {name: pkg.name},
54
56
  });
55
57
  });
56
58
 
57
59
  document.getElementById('initiate-authorization-code-grant').addEventListener('click', () => {
58
60
  webex.config.credentials.clientType = 'confidential';
59
61
  webex.authorization.initiateLogin({
60
- state: {name: pkg.name}
62
+ state: {name: pkg.name},
61
63
  });
62
64
  });
63
65
 
64
66
  document.getElementById('token-refresh').addEventListener('click', () => {
65
67
  document.getElementById('access-token').innerHTML = '';
66
- webex.refresh({force: true})
67
- .then(() => {
68
- document.getElementById('access-token').innerHTML = webex.credentials.supertoken.access_token;
69
- document.getElementById('refresh-token').innerHTML = webex.credentials.supertoken.refresh_token;
70
- });
68
+ webex.refresh({force: true}).then(() => {
69
+ document.getElementById('access-token').innerHTML = webex.credentials.supertoken.access_token;
70
+ document.getElementById('refresh-token').innerHTML = webex.credentials.supertoken.refresh_token;
71
+ });
71
72
  });
72
73
 
73
74
  document.getElementById('logout').addEventListener('click', () => {
@@ -1,22 +1,27 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
- <head>
4
- <title>Authorization Automation Test</title>
5
- </head>
6
- <body class="authorization-automation-test">
7
- <button title="Login with Implicit Grant" id="initiate-implicit-grant">Login with Implicit Grant</button>
8
- <button title="Login with Authorization Code Grant" id="initiate-authorization-code-grant">Login with Authorization Code Grant</button>
9
- <button title="Refresh Access Token" id="token-refresh">Refresh Access Token</button>
3
+ <head>
4
+ <title>Authorization Automation Test</title>
5
+ </head>
6
+ <body class="authorization-automation-test">
7
+ <button title="Login with Implicit Grant" id="initiate-implicit-grant">
8
+ Login with Implicit Grant
9
+ </button>
10
+ <button title="Login with Authorization Code Grant" id="initiate-authorization-code-grant">
11
+ Login with Authorization Code Grant
12
+ </button>
13
+ <button title="Refresh Access Token" id="token-refresh">Refresh Access Token</button>
10
14
 
11
- <h1>Access Token</h1>
12
- <div id="access-token"></div>
13
- <h1>Refresh Token</h1>
14
- <div id="refresh-token"></div>
15
+ <h1>Access Token</h1>
16
+ <div id="access-token"></div>
17
+ <h1>Refresh Token</h1>
18
+ <div id="refresh-token"></div>
15
19
 
16
- <h1>Pinging WDM</h1>
17
- <div id="ping-complete"></div>
20
+ <h1>Pinging WDM</h1>
21
+ <div id="ping-complete"></div>
18
22
 
19
- <button title="Logout" id="logout">Logout</button>
23
+ <button title="Logout" id="logout">Logout</button>
20
24
 
21
- <script src="app.js"></script>
22
- </body>
25
+ <script src="app.js"></script>
26
+ </body>
27
+ </html>
@@ -18,98 +18,106 @@ describe('plugin-authorization-browser', function () {
18
18
  describe.skip('Authorization Code Grant', () => {
19
19
  let browser, user;
20
20
 
21
- before(() => testUsers.create({count: 1})
22
- .then((users) => {
21
+ before(() =>
22
+ testUsers.create({count: 1}).then((users) => {
23
23
  user = users[0];
24
- }));
24
+ })
25
+ );
25
26
 
26
- before(() => createBrowser(pkg)
27
- .then((b) => {
27
+ before(() =>
28
+ createBrowser(pkg).then((b) => {
28
29
  browser = b;
29
- }));
30
+ })
31
+ );
30
32
 
31
33
  after(() => browser && browser.printLogs());
32
34
 
33
- after(() => browser && browser.quit()
34
- .catch((reason) => {
35
- console.warn(reason);
36
- }));
37
-
38
- it('authorizes a user', () => browser
39
- .get(`${redirectUri}/${pkg.name}`)
40
- .waitForElementByClassName('ready')
41
- .title()
35
+ after(
36
+ () =>
37
+ browser &&
38
+ browser.quit().catch((reason) => {
39
+ console.warn(reason);
40
+ })
41
+ );
42
+
43
+ it('authorizes a user', () =>
44
+ browser
45
+ .get(`${redirectUri}/${pkg.name}`)
46
+ .waitForElementByClassName('ready')
47
+ .title()
42
48
  .should.eventually.become('Authorization Automation Test')
43
- .waitForElementByCssSelector('[title="Login with Authorization Code Grant"]')
49
+ .waitForElementByCssSelector('[title="Login with Authorization Code Grant"]')
44
50
  .click()
45
- .login(user)
46
- .waitForElementByClassName('authorization-automation-test')
47
- .waitForElementById('refresh-token')
51
+ .login(user)
52
+ .waitForElementByClassName('authorization-automation-test')
53
+ .waitForElementById('refresh-token')
48
54
  .text()
49
- .should.eventually.not.be.empty
50
- .waitForElementByCssSelector('#ping-complete:not(:empty)')
55
+ .should.eventually.not.be.empty.waitForElementByCssSelector('#ping-complete:not(:empty)')
51
56
  .text()
52
- .should.eventually.become('success'));
57
+ .should.eventually.become('success'));
53
58
 
54
- it('is still logged in after reloading the page', () => browser
55
- .waitForElementById('access-token')
56
- .text()
57
- .should.eventually.not.be.empty
58
- .get(`${redirectUri}/${pkg.name}`)
59
- .sleep(500)
60
- .waitForElementById('access-token')
59
+ it('is still logged in after reloading the page', () =>
60
+ browser
61
+ .waitForElementById('access-token')
61
62
  .text()
62
- .should.eventually.not.be.empty);
63
+ .should.eventually.not.be.empty.get(`${redirectUri}/${pkg.name}`)
64
+ .sleep(500)
65
+ .waitForElementById('access-token')
66
+ .text().should.eventually.not.be.empty);
63
67
 
64
- it('refreshes the user\'s access token', () => {
68
+ it("refreshes the user's access token", () => {
65
69
  let accessToken = '';
66
70
 
67
- return browser
68
- .waitForElementByCssSelector('#access-token:not(:empty)')
71
+ return (
72
+ browser
73
+ .waitForElementByCssSelector('#access-token:not(:empty)')
69
74
  .text()
70
- .then((text) => {
71
- accessToken = text;
72
- assert.isString(accessToken);
73
- assert.isAbove(accessToken.length, 0);
74
-
75
- return browser;
76
- })
77
- .waitForElementByCssSelector('[title="Refresh Access Token"]')
75
+ .then((text) => {
76
+ accessToken = text;
77
+ assert.isString(accessToken);
78
+ assert.isAbove(accessToken.length, 0);
79
+
80
+ return browser;
81
+ })
82
+ .waitForElementByCssSelector('[title="Refresh Access Token"]')
78
83
  .click()
79
- // Not thrilled by a sleep, but we just need to give the button click
80
- // enough time to clear the #access-token box
81
- .sleep(500)
82
- .waitForElementByCssSelector('#access-token:not(:empty)')
84
+ // Not thrilled by a sleep, but we just need to give the button click
85
+ // enough time to clear the #access-token box
86
+ .sleep(500)
87
+ .waitForElementByCssSelector('#access-token:not(:empty)')
83
88
  .text()
84
- .then((text) => {
85
- assert.isString(text);
86
- assert.isAbove(text.length, 0);
87
- assert.notEqual(text, accessToken);
88
-
89
- return browser;
90
- });
89
+ .then((text) => {
90
+ assert.isString(text);
91
+ assert.isAbove(text.length, 0);
92
+ assert.notEqual(text, accessToken);
93
+
94
+ return browser;
95
+ })
96
+ );
91
97
  });
92
98
 
93
- it('logs out a user', () => browser
94
- .title()
99
+ it('logs out a user', () =>
100
+ browser
101
+ .title()
95
102
  .should.eventually.become('Authorization Automation Test')
96
- .waitForElementByCssSelector('[title="Logout"]')
103
+ .waitForElementByCssSelector('[title="Logout"]')
97
104
  .click()
98
- // We need to revoke three tokens before the window.location assignment.
99
- // So far, I haven't found any ques to wait for, so sleep seems to be
100
- // the only option.
101
- .sleep(3000)
102
- .title()
105
+ // We need to revoke three tokens before the window.location assignment.
106
+ // So far, I haven't found any ques to wait for, so sleep seems to be
107
+ // the only option.
108
+ .sleep(3000)
109
+ .title()
103
110
  .should.eventually.become('Redirect Dispatcher')
104
- .get(`${redirectUri}/${pkg.name}`)
105
- .title()
111
+ .get(`${redirectUri}/${pkg.name}`)
112
+ .title()
106
113
  .should.eventually.become('Authorization Automation Test')
107
- .waitForElementById('access-token')
114
+ .waitForElementById('access-token')
108
115
  .text()
109
- .should.eventually.be.empty
110
- .waitForElementByCssSelector('[title="Login with Authorization Code Grant"]')
116
+ .should.eventually.be.empty.waitForElementByCssSelector(
117
+ '[title="Login with Authorization Code Grant"]'
118
+ )
111
119
  .click()
112
- .waitForElementById('IDToken1'));
120
+ .waitForElementById('IDToken1'));
113
121
  });
114
122
  });
115
123
  });
@@ -17,67 +17,74 @@ describe('plugin-authorization-browser', function () {
17
17
  describe.skip('Implicit Grant', () => {
18
18
  let browser, user;
19
19
 
20
- before(() => testUsers.create({count: 1})
21
- .then((users) => {
20
+ before(() =>
21
+ testUsers.create({count: 1}).then((users) => {
22
22
  user = users[0];
23
- }));
23
+ })
24
+ );
24
25
 
25
- before(() => createBrowser(pkg)
26
- .then((b) => {
26
+ before(() =>
27
+ createBrowser(pkg).then((b) => {
27
28
  browser = b;
28
- }));
29
+ })
30
+ );
29
31
 
30
32
  after(() => browser && browser.printLogs());
31
33
 
32
- after(() => browser && browser.quit()
33
- .catch((reason) => {
34
- console.warn(reason);
35
- }));
34
+ after(
35
+ () =>
36
+ browser &&
37
+ browser.quit().catch((reason) => {
38
+ console.warn(reason);
39
+ })
40
+ );
36
41
 
37
- it('authorizes a user', () => browser
38
- .get(`${redirectUri}/${pkg.name}`)
39
- .waitForElementByClassName('ready')
40
- .title()
42
+ it('authorizes a user', () =>
43
+ browser
44
+ .get(`${redirectUri}/${pkg.name}`)
45
+ .waitForElementByClassName('ready')
46
+ .title()
41
47
  .should.eventually.become('Authorization Automation Test')
42
- .waitForElementByCssSelector('[title="Login with Implicit Grant"]')
48
+ .waitForElementByCssSelector('[title="Login with Implicit Grant"]')
43
49
  .click()
44
- .login(user)
45
- .waitForElementByClassName('authorization-automation-test')
46
- .waitForElementByCssSelector('#ping-complete:not(:empty)')
50
+ .login(user)
51
+ .waitForElementByClassName('authorization-automation-test')
52
+ .waitForElementByCssSelector('#ping-complete:not(:empty)')
47
53
  .text()
48
- .should.eventually.become('success'));
54
+ .should.eventually.become('success'));
49
55
 
50
- it('is still logged in after reloading the page', () => browser
51
- .waitForElementById('access-token')
56
+ it('is still logged in after reloading the page', () =>
57
+ browser
58
+ .waitForElementById('access-token')
52
59
  .text()
53
- .should.eventually.not.be.empty
54
- .url()
60
+ .should.eventually.not.be.empty.url()
55
61
  .then((url) => browser.get(url))
56
- .sleep(500)
57
- .waitForElementById('access-token')
58
- .text()
59
- .should.eventually.not.be.empty);
62
+ .sleep(500)
63
+ .waitForElementById('access-token')
64
+ .text().should.eventually.not.be.empty);
60
65
 
61
- it('logs out a user', () => browser
62
- .title()
66
+ it('logs out a user', () =>
67
+ browser
68
+ .title()
63
69
  .should.eventually.become('Authorization Automation Test')
64
- .waitForElementByCssSelector('[title="Logout"]')
70
+ .waitForElementByCssSelector('[title="Logout"]')
65
71
  .click()
66
- // We need to revoke three tokens before the window.location assignment.
67
- // So far, I haven't found any ques to wait for, so sleep seems to be
68
- // the only option.
69
- .sleep(3000)
70
- .title()
72
+ // We need to revoke three tokens before the window.location assignment.
73
+ // So far, I haven't found any ques to wait for, so sleep seems to be
74
+ // the only option.
75
+ .sleep(3000)
76
+ .title()
71
77
  .should.eventually.become('Redirect Dispatcher')
72
- .get(`${redirectUri}/${pkg.name}`)
73
- .title()
78
+ .get(`${redirectUri}/${pkg.name}`)
79
+ .title()
74
80
  .should.eventually.become('Authorization Automation Test')
75
- .waitForElementById('access-token')
81
+ .waitForElementById('access-token')
76
82
  .text()
77
- .should.eventually.be.empty
78
- .waitForElementByCssSelector('[title="Login with Implicit Grant"]')
83
+ .should.eventually.be.empty.waitForElementByCssSelector(
84
+ '[title="Login with Implicit Grant"]'
85
+ )
79
86
  .click()
80
- .waitForElementById('IDToken1'));
87
+ .waitForElementById('IDToken1'));
81
88
  });
82
89
  });
83
90
  });
@@ -17,13 +17,13 @@ browserOnly(describe)('plugin-authorization-browser', () => {
17
17
  const userId = uuid.v4();
18
18
  const displayName = `test-${userId}`;
19
19
 
20
- return createUser({displayName, userId})
21
- .then(({jwt}) => {
22
- const webex = new WebexCore();
20
+ return createUser({displayName, userId}).then(({jwt}) => {
21
+ const webex = new WebexCore();
23
22
 
24
- return webex.authorization.requestAccessTokenFromJwt({jwt})
25
- .then(() => assert.isTrue(webex.canAuthorize));
26
- });
23
+ return webex.authorization
24
+ .requestAccessTokenFromJwt({jwt})
25
+ .then(() => assert.isTrue(webex.canAuthorize));
26
+ });
27
27
  });
28
28
 
29
29
  it('should call services#initServiceCatalogs()', () => {
@@ -39,37 +39,36 @@ browserOnly(describe)('plugin-authorization-browser', () => {
39
39
  });
40
40
  });
41
41
 
42
- describe.skip('\'#refresh', () => {
42
+ describe.skip("'#refresh", () => {
43
43
  describe('when used with an appid access token', () => {
44
44
  it('refreshes the access token', () => {
45
45
  const userId = uuid.v4();
46
46
  const displayName = `test-${userId}`;
47
47
 
48
- return createUser({displayName, userId})
49
- .then(({jwt}) => {
50
- const webex = new WebexCore({
51
- config: {
52
- credentials: {
53
- jwtRefreshCallback() {
54
- return createUser({displayName, userId})
55
- .then(({jwt}) => jwt);
56
- }
57
- }
58
- }
59
- });
60
- let token;
61
-
62
- return webex.authorization.requestAccessTokenFromJwt({jwt})
63
- .then(() => {
64
- token = webex.credentials.supertoken.access_token;
65
- assert.isTrue(webex.canAuthorize);
66
- })
67
- .then(() => webex.refresh())
68
- .then(() => {
69
- assert.isTrue(webex.canAuthorize);
70
- assert.notEqual(webex.credentials.supertoken.access_token, token);
71
- });
48
+ return createUser({displayName, userId}).then(({jwt}) => {
49
+ const webex = new WebexCore({
50
+ config: {
51
+ credentials: {
52
+ jwtRefreshCallback() {
53
+ return createUser({displayName, userId}).then(({jwt}) => jwt);
54
+ },
55
+ },
56
+ },
72
57
  });
58
+ let token;
59
+
60
+ return webex.authorization
61
+ .requestAccessTokenFromJwt({jwt})
62
+ .then(() => {
63
+ token = webex.credentials.supertoken.access_token;
64
+ assert.isTrue(webex.canAuthorize);
65
+ })
66
+ .then(() => webex.refresh())
67
+ .then(() => {
68
+ assert.isTrue(webex.canAuthorize);
69
+ assert.notEqual(webex.credentials.supertoken.access_token, token);
70
+ });
71
+ });
73
72
  });
74
73
  });
75
74
  });