Skip to content

Commit e070c34

Browse files
committed
fix #1209
1 parent e30a4ef commit e070c34

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/requests/consent-request.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,10 @@ class ConsentRequest extends AuthRequest {
9696
let accessModes = []
9797
let consented = false
9898
if (req.body) {
99-
accessModes = req.body.access_mode
99+
accessModes = req.body.access_mode || []
100+
if (!Array.isArray(accessModes)) {
101+
accessModes = [ accessModes ]
102+
}
100103
consented = req.body.consent
101104
}
102105

@@ -155,7 +158,7 @@ class ConsentRequest extends AuthRequest {
155158
return await new Promise(async (resolve, reject) => {
156159
const store = $rdf.graph()
157160
const profileText = await ldp.readResource(webId)
158-
$rdf.parse(profileText.toString(), store, 'https://localhost:8443/profile/card', 'text/turtle', (error, kb) => {
161+
$rdf.parse(profileText.toString(), store, this.getWebIdFile(webId), 'text/turtle', (error, kb) => {
159162
if (error) {
160163
reject(error)
161164
} else {
@@ -166,10 +169,15 @@ class ConsentRequest extends AuthRequest {
166169
}
167170

168171
async saveProfileGraph (ldp, store, webId) {
169-
const text = $rdf.serialize(undefined, store, webId, 'text/turtle')
172+
const text = $rdf.serialize(undefined, store, this.getWebIdFile(webId), 'text/turtle')
170173
await ldp.put(webId, intoStream(text), 'text/turtle')
171174
}
172175

176+
getWebIdFile (webId) {
177+
const webIdurl = new url.URL(webId)
178+
return `${webIdurl.origin}${webIdurl.path}`
179+
}
180+
173181
async isAppRegistered (ldp, appOrigin, webId) {
174182
const store = await this.getProfileGraph(ldp, webId)
175183
return store.each($rdf.sym(webId), ACL('trustedApp')).find((app) => {
@@ -178,6 +186,7 @@ class ConsentRequest extends AuthRequest {
178186
}
179187

180188
async registerApp (ldp, appOrigin, accessModes, webId) {
189+
debug(`Registering app (${appOrigin}) with accessModes ${accessModes} for webId ${webId}`)
181190
const store = await this.getProfileGraph(ldp, webId)
182191
const origin = $rdf.sym(appOrigin)
183192
// remove existing statements on same origin - if it exists
@@ -190,6 +199,7 @@ class ConsentRequest extends AuthRequest {
190199
const application = new $rdf.BlankNode()
191200
store.add($rdf.sym(webId), ACL('trustedApp'), application, webId)
192201
store.add(application, ACL('origin'), origin, webId)
202+
193203
accessModes.forEach(mode => {
194204
store.add(application, ACL('mode'), ACL(mode))
195205
})

0 commit comments

Comments
 (0)