Skip to content

Commit 6085d99

Browse files
Add favicon to demo app, refactor
1 parent 3e31cc5 commit 6085d99

3 files changed

Lines changed: 91 additions & 17 deletions

File tree

‎demo/favicon.png‎

675 Bytes
Loading

‎demo/index.html‎

Lines changed: 84 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<!-- Solid Demo template/stylesheet -->
1010
<link rel="stylesheet" href="./demo.css" />
1111
<!-- Relying Party lib, exports a global var: SolidAuth -->
12-
<script src="../dist/solid-auth-oidc.min.js"></script>
12+
<script src="./client/solid-client.min.js"></script>
1313
</head>
1414
<body>
1515
<div class="container">
@@ -26,43 +26,117 @@ <h5>App body</h5>
2626
<p>The rest of the app goes here</p>
2727
<div class="container">
2828
<div class="row">
29-
<div class="col-md-1 text-right"><code>webId</code></div>
30-
<div class="col-md-11"><code id="webId"></code></div>
29+
<div class="col-md-1 text-right"><strong>WebId</strong></div>
30+
<div class="col-md-4"><code id="webId"></code></div>
31+
<div class="col-md-7">
32+
<div id="noWebId">Not signed in</div>
33+
<div id="logoutDiv" class="hidden">
34+
<button type="button" id="logoutBtn" class="btn btn-primary btn-xs">Log out</button>
35+
</div>
36+
</div>
3137
</div>
3238
<div class="row">
33-
<div class="col-md-1 text-right"><code>provider</code></div>
39+
<div class="col-md-1 text-right"><strong>provider</strong></div>
3440
<div class="col-md-11"><code id="providerUri"></code></div>
3541
</div>
42+
<br /><br />
43+
<div class="row" id="getRootAclDiv" class="hidden">
44+
<div class="col-md-2">
45+
<button type="button" id="getRootAcl" class="btn btn-primary btn-md">
46+
Get Root .acl
47+
</button>
48+
</div>
49+
</div>
50+
<div class="row">
51+
<div class="col-md-12">
52+
<code id="rootAclContents" class="hidden"></code>
53+
</div>
54+
</div>
3655
</div>
3756
</div>
3857
</div>
3958
</body>
4059
<script>
41-
var solid = { auth: new SolidAuth() }
4260

4361
// Using a standard "document loaded" event listener
4462
// (equivalent to jQuery's $(document).ready()
4563
document.addEventListener('DOMContentLoaded', function () {
4664
// Init the solid auth helper, inject whatever behavior you want to happen
4765
// when authentication succeeds.
48-
solid.auth.init({
66+
SolidClient.auth.init({
4967
onLoginSuccess: function (webId, accessToken) {
50-
console.log('onLoginSuccess() callback! webId: ', webId,
51-
'access_token: ', accessToken)
52-
setField('webId', webId)
68+
loginSuccess(webId, accessToken)
5369
},
5470
onProviderSelected: function (providerUri) {
55-
setField('providerUri', providerUri)
71+
providerSelected(providerUri)
5672
}
5773
})
74+
init()
5875
})
5976

77+
function init () {
78+
initButton('getRootAcl', getRootAcl)
79+
initButton('logoutBtn', logout)
80+
}
81+
function initButton(id, action) {
82+
document.getElementById(id).addEventListener('click', action)
83+
}
84+
function loginSuccess (webId, accessToken) {
85+
console.log('onLoginSuccess() callback! webId: ', webId,
86+
'access_token: ', accessToken)
87+
hide('noWebId')
88+
show('logoutDiv')
89+
setField('webId', webId)
90+
show('getRootAclDiv')
91+
}
92+
93+
function logout () {
94+
alert('logging out')
95+
}
96+
97+
function getRootAcl () {
98+
var currentWebId = SolidClient.auth.webId
99+
if (!currentWebId) {
100+
setFieldText('rootAclContents', '')
101+
console.log('Cannot fetch root acl - user not signed in')
102+
return
103+
}
104+
var aclUri = rootAclUri(currentWebId)
105+
console.log('Fetching root acl: ', aclUri)
106+
SolidClient.web.get(aclUri)
107+
.then(function (result) {
108+
show('rootAclContents')
109+
setFieldText('rootAclContents', result.raw())
110+
})
111+
}
112+
113+
function rootAclUri (webId) {
114+
var uri = new URL(webId)
115+
uri.pathname = '/.acl'
116+
uri.hash = ''
117+
return uri.href
118+
}
119+
120+
function providerSelected (providerUri) {
121+
setField('webId', '')
122+
hide('logoutDiv')
123+
hide('getRootAclDiv')
124+
show('noWebId')
125+
setField('providerUri', providerUri)
126+
}
127+
60128
function setField (id, value) {
61129
var field = document.getElementById(id)
62130
if (field) {
63131
field.innerHTML = value
64132
}
65133
}
134+
function setFieldText (id, value) {
135+
var field = document.getElementById(id)
136+
if (field) {
137+
field.innerText = value
138+
}
139+
}
66140
function hide (id) {
67141
document.getElementById(id).className = 'hidden'
68142
}

‎demo/login_iframe_inline.html‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,18 +54,18 @@
5454
<body>
5555
<div class="container">
5656
<div class="row">
57-
<div class="col-sm-2"><strong>Login with:</strong></div>
58-
<div class="col-sm-1">
59-
<button type="button" class="btn btn-xs btn-primary" id="local_provider">
60-
localhost
61-
</button>
62-
</div>
57+
<div class="col-sm-2"><strong>Provider:</strong></div>
6358
<div class="col-sm-2">
6459
<button type="button" class="btn btn-xs btn-primary" id="db_provider">
6560
databox2.com
6661
</button>
6762
</div>
68-
<div class="col-sm-7">
63+
<div class="col-sm-2">
64+
<button type="button" class="btn btn-xs btn-default" id="local_provider">
65+
localhost
66+
</button>
67+
</div>
68+
<div class="col-sm-6">
6969
or custom:
7070
<input type="text" id="custom_provider" value="" placeholder="databox.me" />
7171
</div>

0 commit comments

Comments
 (0)