-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootloader.html
More file actions
214 lines (190 loc) · 7.22 KB
/
bootloader.html
File metadata and controls
214 lines (190 loc) · 7.22 KB
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<!-- Component CSS -->
<style>
</style>
<!-- /Component CSS -->
<!-- Page CSS -->
<style>
</style>
<!-- /Page CSS -->
<!-- Head HTML -->
<!-- metro (baseComponent/metro) -->
<script src="https://cdn.jsdelivr.net/npm/@muze-nl/metro@0.6.19/dist/browser.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@muze-nl/oldm@0.3.6/dist/oldm.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@muze-nl/metro-oauth2@0.7.4/dist/browser.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@muze-nl/metro-oidc@0.5.3/dist/browser.js"></script>
<!-- /Head HTML -->
<script>
var simplyDataApi = {};
var simplyApp = {};
window.addEventListener("simply-content-loaded", function() {
simply.bind = false;
/* Raw API */
var simplyRawApi = {
};
/* End of Raw API */
/* Data API */
simplyDataApi = {
// component/solid-preferences
"getPreferences" : async function(webID){
let issuer = ""
let profileTurtle
const context = oldm.context({
prefixes: {
'ldp': 'http://www.w3.org/ns/ldp#',
'rdf': 'http://www.w3.org/1999/02/22-rdf-syntax-ns#',
'dct': 'http://purl.org/dc/terms/',
'stat': 'http://www.w3.org/ns/posix/stat#',
'turtle': 'http://www.w3.org/ns/iana/media-types/text/turtle#',
'schem': 'https://schema.org/',
'solid': 'http://www.w3.org/ns/solid/terms#',
'acl': 'http://www.w3.org/ns/auth/acl#',
'pims': 'http://www.w3.org/ns/pim/space#',
'vcard': 'http://www.w3.org/2006/vcard/ns#',
'foaf': 'http://xmlns.com/foaf/0.1/'
},
parser: oldm.n3Parser,
writer: oldm.n3Writer
})
//fetch profile to retrieve issuer
const profileURL = webID;
try {
const responseProfile = await fetch(profileURL);
if (!responseProfile.ok) {
throw new Error(`Response status: ${responseProfile.status}`);
}
profileTurtle = await responseProfile.text();
} catch (error) {
console.error(error.message);
}
let podContent = context.parse(profileTurtle, webID, 'text/turtle')
issuer = podContent.primary?.solid$oidcIssuer?.id
let preferenceFileURL = podContent.primary?.pims$preferencesFile?.id
const oidcOptions = {
// authorize_callback: metro.oauth2.authorizePopup,
force_authorization: true,
client_info: {
client_name: 'Solid Bootloader',
redirect_uris: [
window.location.origin + window.location.pathname
]
},
issuer: issuer
}
if (window.location.protocol !== "https") {
// needed to allow app.simplyapp:// as redirect uri
oidcOptions['client_info']['application_type'] = 'native';
}
let client = metro.client().with(metro.oidc.oidcmw(oidcOptions))
let preferenceResponse = await client.get(preferenceFileURL)
if (!preferenceResponse.ok) {
throw new Error(preferenceResponse.status+':'+preferenceResponse.statusText)
}
const preferenceTurtle = await preferenceResponse.text()
let preferenceOLDM = context.parse(preferenceTurtle, preferenceFileURL, 'text/turtle')
return preferenceOLDM
},
// component/bootloader
"appLocation" : async function(webID){
let preferenceOLDM = await simplyDataApi.getPreferences(webID)
if (
preferenceOLDM.subjects[webID] &&
preferenceOLDM.subjects[webID].solid$launcher
) {
return preferenceOLDM.subjects[webID].solid$launcher.id
} else {
return "https://solid-launcher.dev.muze.nl/"
}
}
};
/* End of Data API */
simplyApp = simply.app({
/* Actions */
actions: {
// component/bootloader
"getLauncherLocation" : async function (webID){
let appLauncherPath = await simplyDataApi.appLocation(webID)
return appLauncherPath
}
},
/* /Actions */
/* Commands */
commands: {
},
/* /Commands */
/* Keyboard shortcuts */
keyboard: {
},
/* /Keyboard shortcuts */
/* Routes */
routes: {
// page/home
"#autologin/:webID" : async function(params) {
let webID = params.webID
webID = decodeURIComponent(webID)
localStorage['bootloader:webID'] = webID
let appLauncherPath = await simplyApp.actions.getLauncherLocation(webID)
document.location.href = appLauncherPath + "#autologin/" + encodeURIComponent(webID)
},
// page/home
"/" : async function() {
if (
document.location.search.match("code") ||
document.location.search.match("state")
) {
let webID = localStorage['bootloader:webID']
let appLauncherPath = await simplyApp.actions.getLauncherLocation(webID)
document.location.href = appLauncherPath + "#autologin/" + encodeURIComponent(webID)
}
}
}
/* /Routes */
});
});
function clone(ob) {
return JSON.parse(JSON.stringify(ob));
}
function updateDataSource(name) {
document.querySelectorAll('[data-simply-data="'+name+'"]').forEach(function(list) {
editor.list.applyDataSource(list, name);
list.dataBindingPaused = 0;
});
}
</script>
</head>
<body>
<!-- Body HTML -->
<!-- /Body HTML -->
<!-- Component HTML templates -->
<!-- /Component HTML templates -->
<div class="main" data-simply-field="page" data-simply-content="template">
<!-- Page HTML templates -->
<!-- /Page HTML templates -->
</div>
<script src="https://unpkg.com/simplyview@3.5.5/dist/simply.everything.js"></script>
<script src="https://canary.simplyedit.io/1/simply-edit.js" data-simply-storage="none" data-api-key="simply-edit-0011"></script>
<script>
/* Transformers */
editor.transformers = {
};
/* /Transformers */
</script>
<script>
/* Sorters */
editor.sorters = {
};
/* /Sorters */
</script>
<script>
window.addEventListener("simply-content-loaded", function() {
/* Data sources */
/* /Data sources */
});
</script>
<!-- Foot HTML -->
<!-- /Foot HTML -->
</body>
</html>