-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add WebID attestation for requests to llm_service
This version uses Header parameter for retrieving header. But `Optional` does not seem to be respected correctly.
- Loading branch information
1 parent
6b3c2e7
commit 300f379
Showing
7 changed files
with
386 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const createSolidTokenVerifier = | ||
require("@solid/access-token-verifier").createSolidTokenVerifier; | ||
|
||
/** | ||
* Check whether the request belongs to a / the corresponding WebID. | ||
* @param {string} authorizationHeader The `authorization` header | ||
* @param {string} dpopHeader The `DPoP` header | ||
* @param {string} requestMethod The HTTP method for the request | ||
* @param {string} requestURL The URL of the request | ||
* @param {string|undefined} claimedWebid What WebID the client claims to be (can be `undefined`) | ||
* @returns {boolean|string} If `claimedWebid` is not empty, return whether the claimed WebID matches the real WebID in the credentials; otherwise, return the real WebID. | ||
*/ | ||
async function attestWebidPossession( | ||
authorizationHeader, | ||
dpopHeader, | ||
requestMethod, | ||
requestURL, | ||
claimedWebid | ||
) { | ||
const solidOidcAccessTokenVerifier = createSolidTokenVerifier(); | ||
|
||
try { | ||
const { client_id: clientId, webid: webId } = | ||
await solidOidcAccessTokenVerifier(authorizationHeader, { | ||
header: dpopHeader, | ||
method: requestMethod, | ||
url: requestURL, | ||
}); | ||
|
||
if (!claimedWebid) { | ||
return webId; | ||
} | ||
|
||
return webId == claimedWebid; | ||
} catch (error) { | ||
const message = `Error verifying Access Token via WebID: ${error.message}`; | ||
throw new Error(message); | ||
} | ||
} | ||
|
||
// module.exports = { | ||
// attestWebidPossession, | ||
// }; | ||
|
||
async function main() { | ||
const res = await attestWebidPossession(...process.argv.slice(2)); | ||
|
||
if (res) { | ||
process.exit(0); | ||
} else { | ||
process.exit(1); | ||
} | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.