forked from SolidOS/solid-logic
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauthUtil.js
More file actions
64 lines (64 loc) · 2.56 KB
/
authUtil.js
File metadata and controls
64 lines (64 loc) · 2.56 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
import { sym } from 'rdflib';
import * as debug from '../util/debug';
/**
* find a user or app's context as set in window.SolidAppContext
* this is a const, not a function, because we have problems to jest mock it otherwise
* see: https://github.com/facebook/jest/issues/936#issuecomment-545080082 for more
* @return {any} - an appContext object
*/
export const appContext = () => {
let { SolidAppContext } = window;
SolidAppContext || (SolidAppContext = {});
SolidAppContext.viewingNoAuthPage = false;
if (SolidAppContext.noAuth && window.document) {
const currentPage = window.document.location.href;
if (currentPage.startsWith(SolidAppContext.noAuth)) {
SolidAppContext.viewingNoAuthPage = true;
const params = new URLSearchParams(window.document.location.search);
if (params) {
let viewedPage = SolidAppContext.viewedPage = params.get('uri') || null;
if (viewedPage) {
viewedPage = decodeURI(viewedPage);
if (!viewedPage.startsWith(SolidAppContext.noAuth)) {
const ary = viewedPage.split(/\//);
SolidAppContext.idp = ary[0] + '//' + ary[2];
SolidAppContext.viewingNoAuthPage = false;
}
}
}
}
}
return SolidAppContext;
};
/**
* Returns `sym($SolidTestEnvironment.username)` if
* `$SolidTestEnvironment.username` is defined as a global
* or
* returns testID defined in the HTML page
* @returns {NamedNode|null}
*/
export function offlineTestID() {
const { $SolidTestEnvironment } = window;
if (typeof $SolidTestEnvironment !== 'undefined' &&
$SolidTestEnvironment.username) {
// Test setup
debug.log('Assuming the user is ' + $SolidTestEnvironment.username);
return sym($SolidTestEnvironment.username);
}
// hack that makes SolidOS work in offline mode by adding the webId directly in html
// example usage: https://github.com/solidos/mashlib/blob/29b8b53c46bf02e0e219f0bacd51b0e9951001dd/test/contact/local.html#L37
if (typeof document !== 'undefined' &&
document.location &&
('' + document.location).slice(0, 16) === 'http://localhost') {
const div = document.getElementById('appTarget');
if (!div)
return null;
const id = div.getAttribute('testID');
if (!id)
return null;
debug.log('Assuming user is ' + id);
return sym(id);
}
return null;
}
//# sourceMappingURL=authUtil.js.map