@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/dist/authorization.js +9 -77
- package/dist/authorization.js.map +1 -1
- package/dist/config.js +0 -3
- package/dist/config.js.map +1 -1
- package/dist/index.js +1 -9
- package/dist/index.js.map +1 -1
- package/package.json +14 -14
- package/src/authorization.js +28 -24
- package/src/config.js +2 -2
- package/src/index.js +2 -5
- package/test/automation/fixtures/app.js +25 -24
- package/test/automation/fixtures/index.html +21 -16
- package/test/automation/spec/authorization-code-grant.js +74 -66
- package/test/automation/spec/implicit-grant.js +48 -41
- package/test/integration/spec/authorization.js +30 -31
- package/test/unit/spec/authorization.js +169 -132
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
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
|
40
|
-
|
|
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
|
-
.
|
|
68
|
-
|
|
69
|
-
|
|
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
|
-
|
|
5
|
-
</head>
|
|
6
|
-
<body class="authorization-automation-test">
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
|
|
17
|
-
|
|
20
|
+
<h1>Pinging WDM</h1>
|
|
21
|
+
<div id="ping-complete"></div>
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
<button title="Logout" id="logout">Logout</button>
|
|
20
24
|
|
|
21
|
-
|
|
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(() =>
|
|
22
|
-
.then((users) => {
|
|
21
|
+
before(() =>
|
|
22
|
+
testUsers.create({count: 1}).then((users) => {
|
|
23
23
|
user = users[0];
|
|
24
|
-
})
|
|
24
|
+
})
|
|
25
|
+
);
|
|
25
26
|
|
|
26
|
-
before(() =>
|
|
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(
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
-
|
|
49
|
+
.waitForElementByCssSelector('[title="Login with Authorization Code Grant"]')
|
|
44
50
|
.click()
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
51
|
+
.login(user)
|
|
52
|
+
.waitForElementByClassName('authorization-automation-test')
|
|
53
|
+
.waitForElementById('refresh-token')
|
|
48
54
|
.text()
|
|
49
|
-
|
|
50
|
-
.waitForElementByCssSelector('#ping-complete:not(:empty)')
|
|
55
|
+
.should.eventually.not.be.empty.waitForElementByCssSelector('#ping-complete:not(:empty)')
|
|
51
56
|
.text()
|
|
52
|
-
|
|
57
|
+
.should.eventually.become('success'));
|
|
53
58
|
|
|
54
|
-
it('is still logged in after reloading the page', () =>
|
|
55
|
-
|
|
56
|
-
.
|
|
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
|
-
|
|
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(
|
|
68
|
+
it("refreshes the user's access token", () => {
|
|
65
69
|
let accessToken = '';
|
|
66
70
|
|
|
67
|
-
return
|
|
68
|
-
|
|
71
|
+
return (
|
|
72
|
+
browser
|
|
73
|
+
.waitForElementByCssSelector('#access-token:not(:empty)')
|
|
69
74
|
.text()
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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', () =>
|
|
94
|
-
|
|
99
|
+
it('logs out a user', () =>
|
|
100
|
+
browser
|
|
101
|
+
.title()
|
|
95
102
|
.should.eventually.become('Authorization Automation Test')
|
|
96
|
-
|
|
103
|
+
.waitForElementByCssSelector('[title="Logout"]')
|
|
97
104
|
.click()
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
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
|
-
|
|
105
|
-
|
|
111
|
+
.get(`${redirectUri}/${pkg.name}`)
|
|
112
|
+
.title()
|
|
106
113
|
.should.eventually.become('Authorization Automation Test')
|
|
107
|
-
|
|
114
|
+
.waitForElementById('access-token')
|
|
108
115
|
.text()
|
|
109
|
-
|
|
110
|
-
|
|
116
|
+
.should.eventually.be.empty.waitForElementByCssSelector(
|
|
117
|
+
'[title="Login with Authorization Code Grant"]'
|
|
118
|
+
)
|
|
111
119
|
.click()
|
|
112
|
-
|
|
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(() =>
|
|
21
|
-
.then((users) => {
|
|
20
|
+
before(() =>
|
|
21
|
+
testUsers.create({count: 1}).then((users) => {
|
|
22
22
|
user = users[0];
|
|
23
|
-
})
|
|
23
|
+
})
|
|
24
|
+
);
|
|
24
25
|
|
|
25
|
-
before(() =>
|
|
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(
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
after(
|
|
35
|
+
() =>
|
|
36
|
+
browser &&
|
|
37
|
+
browser.quit().catch((reason) => {
|
|
38
|
+
console.warn(reason);
|
|
39
|
+
})
|
|
40
|
+
);
|
|
36
41
|
|
|
37
|
-
it('authorizes a user', () =>
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
48
|
+
.waitForElementByCssSelector('[title="Login with Implicit Grant"]')
|
|
43
49
|
.click()
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
50
|
+
.login(user)
|
|
51
|
+
.waitForElementByClassName('authorization-automation-test')
|
|
52
|
+
.waitForElementByCssSelector('#ping-complete:not(:empty)')
|
|
47
53
|
.text()
|
|
48
|
-
|
|
54
|
+
.should.eventually.become('success'));
|
|
49
55
|
|
|
50
|
-
it('is still logged in after reloading the page', () =>
|
|
51
|
-
|
|
56
|
+
it('is still logged in after reloading the page', () =>
|
|
57
|
+
browser
|
|
58
|
+
.waitForElementById('access-token')
|
|
52
59
|
.text()
|
|
53
|
-
|
|
54
|
-
.url()
|
|
60
|
+
.should.eventually.not.be.empty.url()
|
|
55
61
|
.then((url) => browser.get(url))
|
|
56
|
-
|
|
57
|
-
|
|
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', () =>
|
|
62
|
-
|
|
66
|
+
it('logs out a user', () =>
|
|
67
|
+
browser
|
|
68
|
+
.title()
|
|
63
69
|
.should.eventually.become('Authorization Automation Test')
|
|
64
|
-
|
|
70
|
+
.waitForElementByCssSelector('[title="Logout"]')
|
|
65
71
|
.click()
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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
|
-
|
|
73
|
-
|
|
78
|
+
.get(`${redirectUri}/${pkg.name}`)
|
|
79
|
+
.title()
|
|
74
80
|
.should.eventually.become('Authorization Automation Test')
|
|
75
|
-
|
|
81
|
+
.waitForElementById('access-token')
|
|
76
82
|
.text()
|
|
77
|
-
|
|
78
|
-
|
|
83
|
+
.should.eventually.be.empty.waitForElementByCssSelector(
|
|
84
|
+
'[title="Login with Implicit Grant"]'
|
|
85
|
+
)
|
|
79
86
|
.click()
|
|
80
|
-
|
|
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
|
-
|
|
22
|
-
const webex = new WebexCore();
|
|
20
|
+
return createUser({displayName, userId}).then(({jwt}) => {
|
|
21
|
+
const webex = new WebexCore();
|
|
23
22
|
|
|
24
|
-
|
|
25
|
-
|
|
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('
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
});
|