pryv 2.1.8 → 2.3.0
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/package.json +12 -45
- package/src/Auth/AuthController.js +43 -50
- package/src/Auth/AuthStates.js +12 -12
- package/src/Auth/LoginMessages.js +17 -14
- package/src/Auth/index.js +18 -15
- package/src/Browser/CookieUtils.js +37 -27
- package/src/Browser/LoginButton.js +42 -37
- package/src/Browser/index.js +16 -42
- package/src/Connection.js +102 -95
- package/src/Service.js +47 -45
- package/src/ServiceAssets.js +42 -34
- package/src/browser-index-bundle.js +8 -0
- package/src/browser-index.js +7 -0
- package/src/index.d.ts +833 -0
- package/src/index.js +20 -3
- package/src/lib/browser-getEventStreamed.js +21 -19
- package/src/lib/json-parser.js +23 -24
- package/src/utils.js +55 -43
- package/test/Browser.AuthController.test.js +19 -21
- package/test/Browser.test.js +23 -26
- package/test/Connection.test.js +164 -162
- package/test/Service.test.js +30 -44
- package/test/ServiceAssets.test.js +16 -22
- package/test/browser-index.html +26 -0
- package/test/utils.test.js +30 -35
- package/.jsdoc-conf.json +0 -29
- package/.mocharc.js +0 -13
- package/LICENSE.md +0 -27
- package/README.md +0 -723
- package/scripts/setup-environment-dev.sh +0 -28
- package/scripts/upload.sh +0 -15
- package/src/Pryv.js +0 -19
- package/src/index-socket.io-monitor.js +0 -4
- package/src/index.html +0 -17
- package/test/browser-index.js +0 -11
- package/test/browser-tests.html +0 -31
- package/test/helpers.js +0 -8
- package/test/load-test-account.js +0 -108
- package/test/test-data.js +0 -92
- package/web-demos/auth-with-redirection.html +0 -72
- package/web-demos/auth.html +0 -77
- package/web-demos/custom-login-button.html +0 -158
- package/web-demos/index.html +0 -186
- package/web-demos/service-info.json +0 -13
- package/web-demos/stream-examples.html +0 -80
- package/webpack.config.js +0 -71
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
|
|
3
|
-
# working dir fix
|
|
4
|
-
scriptsFolder=$(cd $(dirname "$0"); pwd)
|
|
5
|
-
cd $scriptsFolder/..
|
|
6
|
-
|
|
7
|
-
# check for basic prerequisites
|
|
8
|
-
hash git 2>&- || { echo >&2 "I require git."; exit 1; }
|
|
9
|
-
hash npm 2>&- || { echo >&2 "I require Node and NPM."; exit 1; }
|
|
10
|
-
|
|
11
|
-
echo "
|
|
12
|
-
Installing Node modules if necessary...
|
|
13
|
-
"
|
|
14
|
-
npm install
|
|
15
|
-
|
|
16
|
-
distFolder=dist
|
|
17
|
-
if [ ! -d $distFolder ]
|
|
18
|
-
then
|
|
19
|
-
echo "
|
|
20
|
-
Setting up '$distFolder' folder for publishing to GitHub pages...
|
|
21
|
-
"
|
|
22
|
-
git clone -b gh-pages git@github.com:pryv/lib-js.git $distFolder
|
|
23
|
-
fi
|
|
24
|
-
|
|
25
|
-
echo "
|
|
26
|
-
|
|
27
|
-
OK!
|
|
28
|
-
"
|
package/scripts/upload.sh
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
#!/bin/sh
|
|
2
|
-
|
|
3
|
-
set -e
|
|
4
|
-
|
|
5
|
-
# working dir fix
|
|
6
|
-
scriptsFolder=$(cd $(dirname "$0"); pwd)
|
|
7
|
-
cd $scriptsFolder/..
|
|
8
|
-
|
|
9
|
-
if [ $# -eq 0 ]
|
|
10
|
-
then
|
|
11
|
-
echo "No commit message was provided, please provide a message as argument for readability";
|
|
12
|
-
exit 1;
|
|
13
|
-
fi
|
|
14
|
-
|
|
15
|
-
cd dist && git add . && git add -u . && git commit -m "$1" && git push
|
package/src/Pryv.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
/**
|
|
3
|
-
* Pryv library
|
|
4
|
-
* @version 1.0
|
|
5
|
-
* @exports Pryv
|
|
6
|
-
* @property {Pryv.Service} Service - To interact with Pryv.io at a "Platform level"
|
|
7
|
-
* @property {Pryv.Connection} Connection - To interact with an individual's (user) data set
|
|
8
|
-
* @property {Pryv.Browser} Browser - Browser Tools - Access request helpers and visuals (button)
|
|
9
|
-
* @property {Pryv.utils} utils - Exposes **superagent** for HTTP calls and tools to manipulate Pryv's Api Endpoints
|
|
10
|
-
*/
|
|
11
|
-
module.exports = {
|
|
12
|
-
Service: require('./Service'),
|
|
13
|
-
Connection: require('./Connection'),
|
|
14
|
-
Auth: require('./Auth'),
|
|
15
|
-
Browser: require('./Browser'),
|
|
16
|
-
utils: require('./utils'),
|
|
17
|
-
version: require('../package.json').version
|
|
18
|
-
}
|
|
19
|
-
|
package/src/index.html
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Pryv - Light - Javascript Lib</title>
|
|
6
|
-
|
|
7
|
-
<script src="./print.bundle.js"></script>
|
|
8
|
-
</head>
|
|
9
|
-
|
|
10
|
-
<body>
|
|
11
|
-
-
|
|
12
|
-
<script src="./bundle.js"></script>
|
|
13
|
-
+
|
|
14
|
-
<script src="./app.bundle.js"></script>
|
|
15
|
-
</body>
|
|
16
|
-
|
|
17
|
-
</html>
|
package/test/browser-index.js
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Entry Point for WebPack to build test series to be run in browser
|
|
3
|
-
*/
|
|
4
|
-
//mocha.setup({ ignoreLeaks: true });
|
|
5
|
-
|
|
6
|
-
require('./utils.test.js');
|
|
7
|
-
require('./Connection.test.js');
|
|
8
|
-
require('./Service.test.js');
|
|
9
|
-
require('./ServiceAssets.test.js');
|
|
10
|
-
require('./Browser.test.js');
|
|
11
|
-
require('./Browser.AuthController.test.js');
|
package/test/browser-tests.html
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Pryv Javascrip Lib - Browser Tests </title>
|
|
6
|
-
<link rel="stylesheet" href="https://unpkg.com/mocha/mocha.css" />
|
|
7
|
-
</head>
|
|
8
|
-
|
|
9
|
-
<body>
|
|
10
|
-
<div id="mocha"></div>
|
|
11
|
-
<script src="https://unpkg.com/chai/chai.js"></script>
|
|
12
|
-
<script src="https://unpkg.com/mocha/mocha.js"></script>
|
|
13
|
-
<script class="mocha-init">
|
|
14
|
-
mocha.setup('bdd');
|
|
15
|
-
mocha.checkLeaks();
|
|
16
|
-
</script>
|
|
17
|
-
<script src="../pryv.js"></script>
|
|
18
|
-
|
|
19
|
-
<!-- load code you want to test here -->
|
|
20
|
-
<!-- ------------------------------------ -->
|
|
21
|
-
<script type="text/javascript" src="browser-tests.js"></script>
|
|
22
|
-
<!-- ------------------------------------ -->
|
|
23
|
-
<!-- load your test files here -->
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
<script>
|
|
27
|
-
mocha.run();
|
|
28
|
-
</script>
|
|
29
|
-
</body>
|
|
30
|
-
|
|
31
|
-
</html>
|
package/test/helpers.js
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
const testData = require('./test-data.js');
|
|
2
|
-
const Pryv = require('../src');
|
|
3
|
-
|
|
4
|
-
const conn = new Pryv.Connection(testData.apiEndpointWithToken);
|
|
5
|
-
|
|
6
|
-
const TEST_DATA_VERSION = "v1";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
// -- check if account is already loaded
|
|
10
|
-
const res = conn.api([{
|
|
11
|
-
"method": "events.get",
|
|
12
|
-
"params": {
|
|
13
|
-
"streams": ["data"],
|
|
14
|
-
"types": ["test/version"],
|
|
15
|
-
"limit": 1
|
|
16
|
-
}
|
|
17
|
-
}]).then((res, err) => {
|
|
18
|
-
if (res[0].events[0] && res[0].events[0].content === TEST_DATA_VERSION) {
|
|
19
|
-
console.log('TEST ACCOUNT IS UP TO DATE');
|
|
20
|
-
} else {
|
|
21
|
-
doLoad();
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
function doLoad() {
|
|
26
|
-
let query = [
|
|
27
|
-
{ // trash eventual stream data
|
|
28
|
-
"method": "streams.delete",
|
|
29
|
-
"params": {
|
|
30
|
-
"id": "data",
|
|
31
|
-
"mergeEventsWithParent": false
|
|
32
|
-
}
|
|
33
|
-
},
|
|
34
|
-
{ // clear from trash eventual stream data
|
|
35
|
-
"method": "streams.delete",
|
|
36
|
-
"params": {
|
|
37
|
-
"id": "data",
|
|
38
|
-
"mergeEventsWithParent": false
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
{
|
|
42
|
-
"method": "streams.create",
|
|
43
|
-
"params": {
|
|
44
|
-
"id": "data",
|
|
45
|
-
"name": "Test Data",
|
|
46
|
-
"clientData": {
|
|
47
|
-
"pryv-browser:charts": {
|
|
48
|
-
"mass/kg": {
|
|
49
|
-
"settings": {
|
|
50
|
-
"color": "#1abc9c",
|
|
51
|
-
"style": "line",
|
|
52
|
-
"transform": "none",
|
|
53
|
-
"interval": "auto"
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
{
|
|
61
|
-
"method": "events.create",
|
|
62
|
-
"params": {
|
|
63
|
-
"streamId": "data",
|
|
64
|
-
"type": "test/version",
|
|
65
|
-
"content": TEST_DATA_VERSION
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
];
|
|
69
|
-
|
|
70
|
-
const now = (new Date()).getTime() / 1000;
|
|
71
|
-
const steps = 60 * 60 ; // 1 hours
|
|
72
|
-
for (let i = 0; i < 10000; i++) {
|
|
73
|
-
query.push(
|
|
74
|
-
{
|
|
75
|
-
"method": "events.create",
|
|
76
|
-
"params": {
|
|
77
|
-
"time": now - i * steps,
|
|
78
|
-
"streamId": "data",
|
|
79
|
-
"type": "mass/kg",
|
|
80
|
-
"content": Math.sin(i / 180)
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const res = conn.api(query).then((res, err) => {
|
|
87
|
-
trashFirst200DeleteFirst100(res).then((res2, err2) => {
|
|
88
|
-
console.log(res2);
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
async function trashFirst200DeleteFirst100(res) {
|
|
94
|
-
const query = [];
|
|
95
|
-
for (let i = 5; i < 205; i++) {
|
|
96
|
-
const k = (i < 105) ? 2 : 1;
|
|
97
|
-
for (j = 0; j < k; j++) { // do twice for the firsts 100
|
|
98
|
-
console.log(res[i]);
|
|
99
|
-
query.push({
|
|
100
|
-
"method": "events.delete",
|
|
101
|
-
"params": {
|
|
102
|
-
"id": res[i].event.id
|
|
103
|
-
}
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
return await conn.api(query);
|
|
108
|
-
}
|
package/test/test-data.js
DELETED
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
const superagent = require('superagent');
|
|
2
|
-
|
|
3
|
-
const username = 'jslibtest5';
|
|
4
|
-
const serviceInfoUrl = 'https://reg.pryv.me/service/info';
|
|
5
|
-
//const serviceInfoUrl = 'https://l.rec.la:4443/reg/service/info';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Data used for tests
|
|
9
|
-
*/
|
|
10
|
-
const testData = {
|
|
11
|
-
username: username,
|
|
12
|
-
password: username,
|
|
13
|
-
serviceInfoUrl: serviceInfoUrl,
|
|
14
|
-
token: null,
|
|
15
|
-
serviceInfo: null,
|
|
16
|
-
apiEndpoint: null,
|
|
17
|
-
apiEndpointWithToken: null
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
async function prepare() {
|
|
22
|
-
if (testData.token != null) return testData;
|
|
23
|
-
console.log('Preparing test Data..');
|
|
24
|
-
// fetch serviceInfo
|
|
25
|
-
|
|
26
|
-
const serviceInfo = (await superagent.get(serviceInfoUrl)).body;
|
|
27
|
-
if (serviceInfo.api == null) throw 'Invalid service Info ' + JSON.stringify(serviceInfo);
|
|
28
|
-
// test if user exists
|
|
29
|
-
const userExists = (await superagent.get(serviceInfo.register + username + '/check_username')).body;
|
|
30
|
-
if (typeof userExists.reserved === 'undefined') throw 'Invalid user exists ' + JSON.stringify(userExists);
|
|
31
|
-
|
|
32
|
-
let hostingCandidate = null;
|
|
33
|
-
if (! userExists.reserved) { // create user
|
|
34
|
-
// get available hosting
|
|
35
|
-
const hostings = (await superagent.get(serviceInfo.register + 'hostings').set('accept', 'json')).body;
|
|
36
|
-
findOneHostingKey(hostings, 'N');
|
|
37
|
-
function findOneHostingKey(o, parentKey) {
|
|
38
|
-
for (const key of Object.keys(o)) {
|
|
39
|
-
if (parentKey === 'hostings') {
|
|
40
|
-
hostingCandidate = key;
|
|
41
|
-
return key;
|
|
42
|
-
}
|
|
43
|
-
if (typeof o[key] !== 'string')
|
|
44
|
-
findOneHostingKey(o[key], key);
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
if (hostingCandidate == null) throw 'Cannot find hosting in: ' + JSON.stringify(hostings);
|
|
48
|
-
const hosting = hostingCandidate;
|
|
49
|
-
|
|
50
|
-
// create user
|
|
51
|
-
await superagent.post(serviceInfo.register + 'user')
|
|
52
|
-
.send({
|
|
53
|
-
appid: 'js-lib-test',
|
|
54
|
-
hosting: hosting,
|
|
55
|
-
username: username,
|
|
56
|
-
password: username,
|
|
57
|
-
email: username + '@pryv.io',
|
|
58
|
-
invitationtoken: 'enjoy',
|
|
59
|
-
languageCode: 'en',
|
|
60
|
-
referer: 'test-suite'
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
const apiEndpoint = serviceInfo.api.replace('{username}', username);
|
|
64
|
-
// login user
|
|
65
|
-
const loginRes = await superagent.post(apiEndpoint + 'auth/login')
|
|
66
|
-
.set('Origin', 'https://l.rec.la')
|
|
67
|
-
.send({ username: username, password: username, appId: 'js-lib-test' });
|
|
68
|
-
|
|
69
|
-
// create data stream
|
|
70
|
-
try {
|
|
71
|
-
const streamRes = await superagent.post(apiEndpoint + 'streams').set('authorization', loginRes.body.token).send(
|
|
72
|
-
{
|
|
73
|
-
id: 'data',
|
|
74
|
-
name: 'Data'
|
|
75
|
-
}
|
|
76
|
-
)
|
|
77
|
-
} catch (e) {
|
|
78
|
-
}
|
|
79
|
-
if ((loginRes.body == null) || (loginRes.body.token == null)) throw 'Failed login process during testData prepare' + loginRes.text;
|
|
80
|
-
testData.serviceInfo = serviceInfo;
|
|
81
|
-
testData.token = loginRes.body.token;
|
|
82
|
-
|
|
83
|
-
const regexAPIandToken = /(.+):\/\/(.+)/gm;
|
|
84
|
-
const res = regexAPIandToken.exec(apiEndpoint);
|
|
85
|
-
testData.apiEndpointWithToken = res[1] + '://' + testData.token + '@' + res[2];
|
|
86
|
-
testData.apiEndpoint = apiEndpoint;
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
testData.prepare = prepare;
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
module.exports = testData;
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Auth with redirection - Pryv JS lib</title>
|
|
6
|
-
<script src="../pryv.js"></script>
|
|
7
|
-
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
|
8
|
-
<meta content="utf-8" http-equiv="encoding">
|
|
9
|
-
</head>
|
|
10
|
-
|
|
11
|
-
<body>
|
|
12
|
-
<span id="pryv-button"></span>
|
|
13
|
-
<script>
|
|
14
|
-
let authSettings = {
|
|
15
|
-
spanButtonID: 'pryv-button', // span id the DOM that will be replaced by the Service specific button
|
|
16
|
-
onStateChange: function pryvAuthStateChange(state) { // called each time the authentication state changed
|
|
17
|
-
switch(state.id) {
|
|
18
|
-
case Pryv.Auth.AuthStates.LOADING:
|
|
19
|
-
console.log('Loading service information...');
|
|
20
|
-
break;
|
|
21
|
-
case Pryv.Auth.AuthStates.INITIALIZED:
|
|
22
|
-
console.log('Service information is retrieved so authorization can start. You can display login / registration screen or redirect to the our hosted app - web - auth application.');
|
|
23
|
-
break;
|
|
24
|
-
case Pryv.Auth.AuthStates.AUTHORIZED:
|
|
25
|
-
console.log('User is authorized and can access his personal data');
|
|
26
|
-
break;
|
|
27
|
-
case Pryv.Auth.AuthStates.SIGNOUT:
|
|
28
|
-
console.log('User just logged off, please delete all the session related data');
|
|
29
|
-
break;
|
|
30
|
-
case Pryv.Auth.AuthStates.ERROR:
|
|
31
|
-
console.log('Error:', state?.message);
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}, // event Listener for Authentication steps
|
|
35
|
-
authRequest: { // See: https://api.pryv.com/reference/#auth-request
|
|
36
|
-
requestingAppId: 'lib-js-test',
|
|
37
|
-
languageCode: 'fr', // optional (default english)
|
|
38
|
-
returnURL: 'auto#',
|
|
39
|
-
requestedPermissions: [{
|
|
40
|
-
streamId: 'test',
|
|
41
|
-
defaultName: 'Test',
|
|
42
|
-
level: 'read',
|
|
43
|
-
}],
|
|
44
|
-
// the login page where user will be redirected
|
|
45
|
-
returnURL: 'https://l.rec.la:9443/demos/auth-with-redirection.html#'
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const serviceInfoUrl = null; // 'https://api.pryv.com/lib-js/demos/service-info.json';
|
|
50
|
-
const serviceInfoJson = {
|
|
51
|
-
"register": "https://reg.pryv.me",
|
|
52
|
-
"access": "https://access.pryv.me/access",
|
|
53
|
-
"api": "https://{username}.pryv.me/",
|
|
54
|
-
"name": "Pryv Lab",
|
|
55
|
-
"home": "https://www.pryv.com",
|
|
56
|
-
"support": "https://pryv.com/helpdesk",
|
|
57
|
-
"terms": "https://pryv.com/pryv-lab-terms-of-use/",
|
|
58
|
-
"eventTypes": "https://api.pryv.com/event-types/flat.json",
|
|
59
|
-
"assets": {
|
|
60
|
-
"definitions": "https://pryv.github.io/assets-pryv.me/index.json"
|
|
61
|
-
}};
|
|
62
|
-
(async function () {
|
|
63
|
-
let service = await Pryv.Auth.setupAuth(
|
|
64
|
-
authSettings,
|
|
65
|
-
serviceInfoUrl,
|
|
66
|
-
serviceInfoJson
|
|
67
|
-
);
|
|
68
|
-
})();
|
|
69
|
-
</script>
|
|
70
|
-
</body>
|
|
71
|
-
|
|
72
|
-
</html>
|
package/web-demos/auth.html
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Auth - Pryv JS lib</title>
|
|
6
|
-
<script src="../pryv.js"></script>
|
|
7
|
-
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
|
8
|
-
<meta content="utf-8" http-equiv="encoding">
|
|
9
|
-
</head>
|
|
10
|
-
|
|
11
|
-
<body>
|
|
12
|
-
<span id="pryv-button"></span>
|
|
13
|
-
<script>
|
|
14
|
-
const authSettings = {
|
|
15
|
-
spanButtonID: 'pryv-button', // span id the DOM that will be replaced by the Service specific button
|
|
16
|
-
onStateChange: function pryvAuthStateChange(state) { // called each time the authentication state changed
|
|
17
|
-
switch(state.id) {
|
|
18
|
-
case Pryv.Auth.AuthStates.LOADING:
|
|
19
|
-
console.log('Loading service information...');
|
|
20
|
-
break;
|
|
21
|
-
case Pryv.Auth.AuthStates.INITIALIZED:
|
|
22
|
-
console.log('Service information is retrieved so authorization can start. You can display login / registration screen or redirect to the our hosted app - web - auth application.');
|
|
23
|
-
break;
|
|
24
|
-
case Pryv.Auth.AuthStates.AUTHORIZED:
|
|
25
|
-
console.log('User is authorized and can access his personal data');
|
|
26
|
-
break;
|
|
27
|
-
case Pryv.Auth.AuthStates.SIGNOUT:
|
|
28
|
-
console.log('User just logged off, please delete all the session related data');
|
|
29
|
-
break;
|
|
30
|
-
case Pryv.Auth.AuthStates.ERROR:
|
|
31
|
-
console.log('Error:', state?.message);
|
|
32
|
-
break;
|
|
33
|
-
}
|
|
34
|
-
}, // event Listener for Authentication steps
|
|
35
|
-
authRequest: { // See: https://api.pryv.com/reference/#auth-request
|
|
36
|
-
requestingAppId: 'lib-js-test',
|
|
37
|
-
requestedPermissions: [
|
|
38
|
-
{
|
|
39
|
-
streamId: 'test',
|
|
40
|
-
defaultName: 'test',
|
|
41
|
-
level: 'manage'
|
|
42
|
-
}
|
|
43
|
-
],
|
|
44
|
-
clientData: {
|
|
45
|
-
'app-web-auth:description': {
|
|
46
|
-
'type': 'note/txt',
|
|
47
|
-
'content': 'This is a consent message.'
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
// referer: 'my test with lib-js', // optional string to track registration source
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const serviceInfoUrl = null;// 'https://api.pryv.com/lib-js/demos/service-info.json';
|
|
55
|
-
const serviceInfoJson = {
|
|
56
|
-
"register": "https://reg.pryv.me",
|
|
57
|
-
"access": "https://access.pryv.me/access",
|
|
58
|
-
"api": "https://{username}.pryv.me/",
|
|
59
|
-
"name": "Pryv Lab",
|
|
60
|
-
"home": "https://www.pryv.com",
|
|
61
|
-
"support": "https://pryv.com/helpdesk",
|
|
62
|
-
"terms": "https://pryv.com/pryv-lab-terms-of-use/",
|
|
63
|
-
"eventTypes": "https://api.pryv.com/event-types/flat.json",
|
|
64
|
-
"assets": {
|
|
65
|
-
"definitions": "https://pryv.github.io/assets-pryv.me/index.json"
|
|
66
|
-
}};
|
|
67
|
-
(async function () {
|
|
68
|
-
service = await Pryv.Auth.setupAuth(
|
|
69
|
-
authSettings,
|
|
70
|
-
serviceInfoUrl,
|
|
71
|
-
serviceInfoJson
|
|
72
|
-
);
|
|
73
|
-
})();
|
|
74
|
-
</script>
|
|
75
|
-
</body>
|
|
76
|
-
|
|
77
|
-
</html>
|
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html>
|
|
3
|
-
|
|
4
|
-
<head>
|
|
5
|
-
<title>Custom Login button - Pryv JS lib</title>
|
|
6
|
-
<script src="../pryv.js"></script>
|
|
7
|
-
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
|
|
8
|
-
<meta content="utf-8" http-equiv="encoding">
|
|
9
|
-
</head>
|
|
10
|
-
|
|
11
|
-
<body>
|
|
12
|
-
<button type="button" id="pryv-button">My custom button</button>
|
|
13
|
-
<script>
|
|
14
|
-
const authSettings = {
|
|
15
|
-
spanButtonID: 'pryv-button', // span id the DOM that will be replaced by the Service specific button
|
|
16
|
-
authRequest: { // See: https://api.pryv.com/reference/#auth-request
|
|
17
|
-
requestingAppId: 'custom-login-button-example',
|
|
18
|
-
requestedPermissions: [
|
|
19
|
-
{
|
|
20
|
-
streamId: 'test',
|
|
21
|
-
defaultName: 'test',
|
|
22
|
-
level: 'manage'
|
|
23
|
-
}
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
class MyLoginButton {
|
|
29
|
-
|
|
30
|
-
constructor(authSettings, service) {
|
|
31
|
-
this.authSettings = authSettings;
|
|
32
|
-
this.service = service;
|
|
33
|
-
this.serviceInfo = service.infoSync();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
async init() {
|
|
37
|
-
const loginButtonSpan = document.getElementById(this.authSettings.spanButtonID);
|
|
38
|
-
loginButtonSpan.addEventListener('click', this.onClick.bind(this));
|
|
39
|
-
this.loginButtonSpan = loginButtonSpan;
|
|
40
|
-
|
|
41
|
-
this._cookieKey = 'pryv-libjs-' + this.authSettings.authRequest.requestingAppId;
|
|
42
|
-
|
|
43
|
-
this.auth = new Pryv.Auth.AuthController(this.authSettings, this.service, this);
|
|
44
|
-
await this.auth.init();
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
onClick() {
|
|
48
|
-
this.auth.handleClick();
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
async onStateChange (state) {
|
|
52
|
-
switch (state.status) {
|
|
53
|
-
case Pryv.Auth.AuthStates.LOADING:
|
|
54
|
-
this.text = 'Loading visual assets';
|
|
55
|
-
break;
|
|
56
|
-
case Pryv.Auth.AuthStates.INITIALIZED:
|
|
57
|
-
this.text = 'Sign into: ' + this.serviceInfo.name;
|
|
58
|
-
break;
|
|
59
|
-
case Pryv.Auth.AuthStates.NEED_SIGNIN:
|
|
60
|
-
const loginUrl = state.authUrl || state.url; // .url is deprecated
|
|
61
|
-
if (this.authSettings.authRequest.returnURL) { // open on same page (no Popup)
|
|
62
|
-
location.href = loginUrl;
|
|
63
|
-
return;
|
|
64
|
-
} else {
|
|
65
|
-
startLoginScreen(this, loginUrl);
|
|
66
|
-
}
|
|
67
|
-
break;
|
|
68
|
-
case Pryv.Auth.AuthStates.AUTHORIZED:
|
|
69
|
-
this.text = 'Signed in as ' + state.username;
|
|
70
|
-
this.saveAuthorizationData({
|
|
71
|
-
apiEndpoint: state.apiEndpoint,
|
|
72
|
-
username: state.username
|
|
73
|
-
});
|
|
74
|
-
break;
|
|
75
|
-
case Pryv.Auth.AuthStates.SIGNOUT:
|
|
76
|
-
const message = 'Do you wish to sign out?';
|
|
77
|
-
if (confirm(message)) {
|
|
78
|
-
this.deleteAuthorizationData();
|
|
79
|
-
this.auth.init();
|
|
80
|
-
}
|
|
81
|
-
break;
|
|
82
|
-
case Pryv.Auth.AuthStates.ERROR:
|
|
83
|
-
this.text = getErrorMessage(this, state.message);
|
|
84
|
-
break;
|
|
85
|
-
default:
|
|
86
|
-
console.log('WARNING Unhandled state for Login: ' + state.status);
|
|
87
|
-
}
|
|
88
|
-
if (this.loginButtonSpan) {
|
|
89
|
-
this.loginButtonSpan.innerHTML = this.text;
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
saveAuthorizationData(authData) {
|
|
94
|
-
console.log('You should save this object to the storage', authData);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
getAuthorizationData() {
|
|
98
|
-
return Pryv.Browser.CookieUtils.get(this._cookieKey);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
async deleteAuthorizationData() {
|
|
102
|
-
console.log('You should delete saved data from the storage');
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function startLoginScreen(loginButton, authUrl) {
|
|
107
|
-
console.log('My custom popup that is huge:');
|
|
108
|
-
let screenX = typeof window.screenX !== 'undefined' ? window.screenX : window.screenLeft,
|
|
109
|
-
screenY = typeof window.screenY !== 'undefined' ? window.screenY : window.screenTop,
|
|
110
|
-
outerWidth = typeof window.outerWidth !== 'undefined' ?
|
|
111
|
-
window.outerWidth : document.body.clientWidth,
|
|
112
|
-
outerHeight = typeof window.outerHeight !== 'undefined' ?
|
|
113
|
-
window.outerHeight : (document.body.clientHeight - 22),
|
|
114
|
-
width = 900,
|
|
115
|
-
height = 500,
|
|
116
|
-
left = parseInt(screenX + ((outerWidth - width) / 2), 10),
|
|
117
|
-
top = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
|
|
118
|
-
features = (
|
|
119
|
-
'width=' + width +
|
|
120
|
-
',height=' + height +
|
|
121
|
-
',left=' + left +
|
|
122
|
-
',top=' + top +
|
|
123
|
-
',scrollbars=yes'
|
|
124
|
-
);
|
|
125
|
-
loginButton.popup = window.open(authUrl, 'Your custom Sign-in pop-up', features);
|
|
126
|
-
|
|
127
|
-
if (!loginButton.popup) {
|
|
128
|
-
console.log('Pop-up blocked. A second click should allow it.');
|
|
129
|
-
} else if (window.focus) {
|
|
130
|
-
loginButton.popup.focus();
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
const serviceInfoUrl = null; // 'https://api.pryv.com/lib-js/demos/service-info.json';
|
|
135
|
-
const serviceInfoJson = {
|
|
136
|
-
"register": "https://reg.pryv.me",
|
|
137
|
-
"access": "https://access.pryv.me/access",
|
|
138
|
-
"api": "https://{username}.pryv.me/",
|
|
139
|
-
"name": "Pryv Lab",
|
|
140
|
-
"home": "https://www.pryv.com",
|
|
141
|
-
"support": "https://pryv.com/helpdesk",
|
|
142
|
-
"terms": "https://pryv.com/pryv-lab-terms-of-use/",
|
|
143
|
-
"eventTypes": "https://api.pryv.com/event-types/flat.json",
|
|
144
|
-
"assets": {
|
|
145
|
-
"definitions": "https://pryv.github.io/assets-pryv.me/index.json"
|
|
146
|
-
}};
|
|
147
|
-
(async function () {
|
|
148
|
-
let service = await Pryv.Auth.setupAuth(
|
|
149
|
-
authSettings,
|
|
150
|
-
serviceInfoUrl,
|
|
151
|
-
serviceInfoJson,
|
|
152
|
-
MyLoginButton,
|
|
153
|
-
);
|
|
154
|
-
})();
|
|
155
|
-
</script>
|
|
156
|
-
</body>
|
|
157
|
-
|
|
158
|
-
</html>
|