-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathauth.html
86 lines (81 loc) · 3.21 KB
/
auth.html
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
<!doctype html>
<html lang="en">
<head>
<title>Auth — Pryv JS lib example</title>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta http-equiv="X-UA-Compatible" content="ie=edge" />
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto+Condensed:300,400,700" type="text/css">
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,400,500,400italic" type="text/css">
<link rel="stylesheet" type="text/css" href="https://api.pryv.com/style/pryv.min.css">
<!-- Paths assume we're in dist/examples/ (update as needed) -->
<script src="../pryv.js"></script>
</head>
<body>
<div class="container container-narrow">
<h1>Example: Auth</h1>
<span id="pryv-button"></span>
</div>
<script>
const authSettings = {
spanButtonID: 'pryv-button', // span id the DOM that will be replaced by the Service specific button
onStateChange: function authStateChanged(state) { // called each time the authentication state changed
switch(state.id) {
case pryv.Auth.AuthStates.LOADING:
console.log('Loading service information...');
break;
case pryv.Auth.AuthStates.INITIALIZED:
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.');
break;
case pryv.Auth.AuthStates.AUTHORIZED:
console.log('User is authorized and can access his personal data');
break;
case pryv.Auth.AuthStates.SIGNOUT:
console.log('User just logged off, please delete all the session related data');
break;
case pryv.Auth.AuthStates.ERROR:
console.log('Error:', state?.message);
break;
}
}, // event Listener for Authentication steps
authRequest: { // See: https://api.pryv.com/reference/#auth-request
requestingAppId: 'lib-js-test',
requestedPermissions: [
{
streamId: 'test',
defaultName: 'test',
level: 'manage'
}
],
clientData: {
'app-web-auth:description': {
'type': 'note/txt',
'content': 'This is a consent message.'
}
},
// referer: 'my test with lib-js', // optional string to track registration source
}
};
const serviceInfoUrl = null;// 'https://api.pryv.com/lib-js/demos/service-info.json';
const serviceInfoJson = {
"register": "https://reg.pryv.me",
"access": "https://access.pryv.me/access",
"api": "https://{username}.pryv.me/",
"name": "Pryv Lab",
"home": "https://www.pryv.com",
"support": "https://pryv.com/helpdesk",
"terms": "https://pryv.com/pryv-lab-terms-of-use/",
"eventTypes": "https://api.pryv.com/event-types/flat.json",
"assets": {
"definitions": "https://pryv.github.io/assets-pryv.me/index.json"
}};
(async function () {
service = await pryv.Auth.setupAuth(
authSettings,
serviceInfoUrl,
serviceInfoJson
);
})();
</script>
</body>
</html>