-
Notifications
You must be signed in to change notification settings - Fork 9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support of multi oidcIssuer relations per one user's profile #30
base: main
Are you sure you want to change the base?
Changes from all commits
08f9ff1
0b830b1
609911b
5d2eb8c
945d9f4
003926f
bd61dbc
1d75ade
4a4d399
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,20 +61,48 @@ function providerExists (uri) { | |
* given Web ID, extracted from Link rel header or profile body. If no | ||
* provider URI was found, reject with an error. | ||
*/ | ||
function discoverProviderFor (webId) { | ||
function discoverProviderFor (webId, issuer) { | ||
return discoverFromHeaders(webId) | ||
|
||
.then(providerFromHeaders => providerFromHeaders || discoverFromProfile(webId)) | ||
.then(providerFromHeaders => providerFromHeaders || discoverAllFromProfile(webId)) | ||
|
||
.then(providerUri => { | ||
// drop the path (provider origin only) | ||
if (providerUri) { | ||
providerUri = (new URL(providerUri)).origin | ||
if (Array.isArray(providerUri)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not good; should always be an array. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could force it into an array with |
||
let list = providerUri | ||
let lastErr = null | ||
|
||
for (let i = 0; i < list.length; i++) { | ||
lastErr = null | ||
providerUri = list[i] | ||
if (providerUri) { | ||
providerUri = (new URL(providerUri)).origin | ||
} | ||
|
||
try { | ||
validateProviderUri(providerUri, webId) // Throw an error if empty or invalid | ||
} catch (err) { | ||
lastErr = err | ||
} | ||
|
||
if (lastErr === null && ((issuer && providerUri === issuer) || !issuer)) { | ||
return providerUri | ||
} | ||
} | ||
if (lastErr) { | ||
throw lastErr | ||
} else { | ||
validateProviderUri(null, webId) // Throw an error if empty or invalid | ||
} | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above logic is very messy. |
||
// drop the path (provider origin only) | ||
if (providerUri) { | ||
providerUri = (new URL(providerUri)).origin | ||
} | ||
|
||
validateProviderUri(providerUri, webId) // Throw an error if empty or invalid | ||
|
||
return providerUri | ||
} | ||
|
||
validateProviderUri(providerUri, webId) // Throw an error if empty or invalid | ||
|
||
return providerUri | ||
}) | ||
} | ||
|
||
|
@@ -94,16 +122,30 @@ function discoverFromHeaders (webId) { | |
}) | ||
} | ||
|
||
function discoverFromProfile (webId) { | ||
function discoverAllFromProfile (webId) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this should then also become |
||
const store = rdf.graph() | ||
|
||
const fetcher = rdf.fetcher(store) | ||
|
||
return fetcher.load(webId, { force: true }) | ||
.then(response => { | ||
if (!response.ok) { | ||
let error = new Error(`Could not reach Web ID ${webId} to discover provider`) | ||
error.statusCode = 400 | ||
throw error | ||
} | ||
|
||
let providerTerm = rdf.namedNode('http://www.w3.org/ns/solid/terms#oidcIssuer') | ||
let providerUri = store.anyValue(rdf.namedNode(webId), providerTerm) | ||
return providerUri | ||
let idp = store.each(rdf.namedNode(webId), providerTerm, undefined) | ||
let list = [] | ||
|
||
for (let i = 0; i < idp.length; i++) { | ||
if (idp[i].uri) { | ||
list.push(idp[i].uri) | ||
} | ||
} | ||
|
||
return list | ||
}, err => { | ||
let error = new Error(`Could not reach Web ID ${webId} to discover provider`) | ||
error.cause = err | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module.exports = ` | ||
@prefix solid: <http://www.w3.org/ns/solid/terms#>. | ||
@prefix foaf: <http://xmlns.com/foaf/0.1/>. | ||
@prefix pim: <http://www.w3.org/ns/pim/space#>. | ||
@prefix schema: <http://schema.org/>. | ||
@prefix ldp: <http://www.w3.org/ns/ldp#>. | ||
|
||
<> | ||
a foaf:PersonalProfileDocument ; | ||
foaf:primaryTopic <#me> . | ||
|
||
<#me> | ||
a schema:Person ; | ||
|
||
solid:account </> ; # link to the account uri | ||
pim:storage </> ; # root storage | ||
|
||
solid:oidcIssuer <https://provider2.com> ; | ||
solid:oidcIssuer <https://provider.com> . | ||
` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the method functionality has changed from discovering to validating? We probably need a method like
isValidProvider
then.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will update the code.
I tried to create fix with a minimal changes in the code.