profile
viewpoint
Read-Write Linked Data linkeddata MIT Originally MIT code. Everything must be MIT Licence.

linkeddata/dokieli 616

:bulb: dokieli is a clientside editor for decentralised article publishing, annotations and social interactions

linkeddata/rdflib.js 480

Linked Data API for JavaScript

linkeddata/gold 142

Linked Data server for Go

linkeddata/cimba 98

Client-Integrated Micro-Blogging Architecture application

linkeddata/profile-editor 46

WebID profile editor

linkeddata/ldphp 38

Linked Data server for PHP

linkeddata/node-webid 37

WebID node.js library

linkeddata/contacts 36

Address book-like application to manage contact information.

linkeddata/ontology-archiver 21

Copy favorite and commonly used RDF schemas/ontologies to a safe place

fork developermuhsin/project-roadmap

Roadmap and wishlist for the Crosscloud project

fork in an hour

push eventlinkeddata/rdflib.js

bourgeoa

commit sha 4bdf7e00dc9a7ed59402b46deb5503068e10808c

deploy: 1a90b03cef433f456d518e16440fb0281368c445

view details

push time in 3 days

push eventlinkeddata/rdflib.js

bourgeoa

commit sha 811bf588851faf51a2ad3cc9d01372c0cf4b8c46

deploy: ec4ac9e055946ee4a9caef76fd37ced4e9b12e7a

view details

push time in 3 days

push eventlinkeddata/rdflib.js

Jeff Zucker

commit sha e09638a790ea69efd0cdb19eac30e7218c341a72

Update README.md Add link to new documentation on authenticated & alternate fetches.

view details

Alain Bourgeois

commit sha 1a90b03cef433f456d518e16440fb0281368c445

Merge pull request #533 from linkeddata/jeff-zucker-alternate-fetches-readme Update README.md

view details

push time in 3 days

PR merged linkeddata/rdflib.js

Update README.md

Add link to new documentation on authenticated & alternate fetches.

+1 -0

0 comment

1 changed file

jeff-zucker

pr closed time in 3 days

push eventlinkeddata/rdflib.js

Jeff Zucker

commit sha df282cc04a3eb404fa39c161d28f50c0a180fdda

Create alternate-fetches.md Documentation for authenticated and alternate fetch methods.

view details

Jeff Zucker

commit sha 495b7ae6616d943f68be8e5e963e2267afc10b6d

Update Documentation/alternate-fetches.md Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>

view details

Jeff Zucker

commit sha 1329dd5f1f4d127494a6f86ef20a84b77c780262

Update Documentation/alternate-fetches.md Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>

view details

Jeff Zucker

commit sha 90af0da7aaf0123fb60132f4a8f8eb44f52555e9

Update Documentation/alternate-fetches.md Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>

view details

Jeff Zucker

commit sha 8c5fe1cf8770590148233f4aaff50f0d4a8d5d5d

Update Documentation/alternate-fetches.md Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>

view details

Jeff Zucker

commit sha 0c4f9b8a67163e7b30d9f9a1ebbc5e4ebcd73f90

Update Documentation/alternate-fetches.md Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>

view details

Jeff Zucker

commit sha dfd110d9778ccaaf1b3144f32b630322c75fead1

Update Documentation/alternate-fetches.md Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>

view details

Jeff Zucker

commit sha 96ff94a37428dfe4f1676736dccc4b515cb54bee

Update Documentation/alternate-fetches.md Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>

view details

Jeff Zucker

commit sha 0e27fde7621f2d55b1b9cb5002f12c98e0bbdda7

Update Documentation/alternate-fetches.md Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>

view details

Jeff Zucker

commit sha ca454939325dd3c5dc128a2486c61f5260f197e5

Update Documentation/alternate-fetches.md Co-authored-by: Alain Bourgeois <alain.bourgeois10@gmail.com>

view details

jeff-zucker

commit sha 8b1f73cc2b46eb07b94c379da3da6b564afb93fb

added text on global vars

view details

Alain Bourgeois

commit sha ec4ac9e055946ee4a9caef76fd37ced4e9b12e7a

Merge pull request #532 from linkeddata/jeff-zucker-alternate-fetches Create alternate-fetches.md

view details

push time in 3 days

PR merged linkeddata/rdflib.js

Create alternate-fetches.md

Documentation for authenticated and alternate fetch methods. This should resolve https://github.com/linkeddata/rdflib.js/issues/531.

+87 -0

3 comments

1 changed file

jeff-zucker

pr closed time in 3 days

issue closedlinkeddata/rdflib.js

How-to add a user-defined fetch()

There is no documentation on how-to replace the default fetch() by a user defined one. This a frequent developer question.

closed time in 3 days

bourgeoa
PullRequestReviewEvent
PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentlinkeddata/rdflib.js

Create alternate-fetches.md

+# Using authenticated and alternate fetches in rdflib++By default, `rdflib`'s fetcher uses `cross-fetch.fetch()` to preform reads and writes.  This is a plain `fetch`, similar to `wget` or `curl`, that does not carry any authentication information.  To use `rdflib` with private Solid data that requires authentication, the user or app needs to pass a different fetch method to `rdflib`.  This approach is also useful if you have created your own fetch, such as against Dropbox or a database.                                                                       ++## The solidFetch variable                                                ++To use an authenticated or alternate fetch with `rdflib`++1. Load the authentication library.+2. Use it to log in to your identity provider.+3a. Set the `global.solidFetch` (or `window.solidFetch` in a browser) equal to the auth library's fetch method.+3b. OR see below to create a custom fetcher+4. Load and use `rdflib`.  All fetches will be authenticated.++_**Important Note:** Prior to `rdflib` version `2.2.9`, this variable was named `solidFetcher`, so use that with older `rdflib`s.  Going forward, please use `solidFetch`._++### A CLI (out-of-browser) Example++```javascript                                                                   +async function test() {+    const auth = new (require("solid-node-client").SolidNodeClient)();+    await auth.login( your-credentials );                             +    global.solidFetch = auth.fetch;                                   +    const $rdf = global.$rdf = require('rdflib');                     +    const kb = $rdf.graph(); +    const fetcher = $rdf.fetcher(kb);+    await fetcher.load( some-private-url );  +}+```               ++### A Browser Example++This is a fully functional script; just change the `IdP` and `privateResource` addresses.++```html+<!DOCTYPE html><html><head><meta charset="UTF-8" />                             +    <script src="https://cdn.jsdelivr.net/npm/@inrupt/solid-client-authn-browse\+r@1.11.2/dist/solid-client-authn.bundle.js"></script>                           +    <script src="https://cdn.jsdelivr.net/npm/rdflib@2.2.6/dist/rdflib.min.js">\+</script>                                                                       +</head><body>                                                                   +    <button id="login">go</button>                                              +</body>                                                                         +<script>                                                                        +    const idp = "https://solidcommunity.net";                                   +    const privateResource = "https://jeff-zucker.solidcommunity.net/private/";  +    const auth = solidClientAuthentication;                                     +    async function main(session){                                               +        const kb = $rdf.graph();                                                +        window.solidFetcher = session.fetch;                                    +        const fetcher = $rdf.fetcher(kb)                                        +        try {                                                                   +          await fetcher.load(privateResource);                                  +          alert("Private resource successfully loaded");                        +        }                                                                       +        catch(e) { alert(e) }                                                   +    }                                                                           +    document.getElementById('login').onclick = ()=> {                           +        auth.login({                                                            +            oidcIssuer: idp,                                                    +            redirectUrl: window.location.href,                                  +            clientName: "rdflib test"                                           +        });                                                                     +    }                                                                           +    async function handleRedirectAfterLogin() {                                 +        await auth.handleIncomingRedirect();                                    +        session = auth.getDefaultSession();                                     +        if (session.info.isLoggedIn)  main(session);                            +    }                                                                           +    handleRedirectAfterLogin();                                                 +</script></html>                                                                +```+++##  Custom fetchers++Another way to specify an authenticated or alternate fetch is to do it when you create the fetcher object.  This method follows the same steps as the first method, with two exceptions: omit the line *`global.solidFetch = auth.fetch`*; and instead of the line *`const fetcher = $rdf.fetcher(kb)`* use :+```javascript+const fetcher = $rdf.fetcher(kb,{fetch:auth.fetch.bind(auth)});+```+Doing things this way avoids using global variables, but also means that the changes to fetch need to be added every time you create a new fetcher object.

Worth checking, though, thanks for your careful eye.

jeff-zucker

comment created time in 4 days

Pull request review commentlinkeddata/rdflib.js

Create alternate-fetches.md

+# Using authenticated and alternate fetches in rdflib++By default, `rdflib`'s fetcher uses `cross-fetch.fetch()` to preform reads and writes.  This is a plain `fetch`, similar to `wget` or `curl`, that does not carry any authentication information.  To use `rdflib` with private Solid data that requires authentication, the user or app needs to pass a different fetch method to `rdflib`.  This approach is also useful if you have created your own fetch, such as against Dropbox or a database.                                                                       ++## The solidFetch variable                                                ++To use an authenticated or alternate fetch with `rdflib`++1. Load the authentication library.+2. Use it to log in to your identity provider.+3a. Set the `global.solidFetch` (or `window.solidFetch` in a browser) equal to the auth library's fetch method.+3b. OR see below to create a custom fetcher+4. Load and use `rdflib`.  All fetches will be authenticated.++_**Important Note:** Prior to `rdflib` version `2.2.9`, this variable was named `solidFetcher`, so use that with older `rdflib`s.  Going forward, please use `solidFetch`._++### A CLI (out-of-browser) Example++```javascript                                                                   +async function test() {+    const auth = new (require("solid-node-client").SolidNodeClient)();+    await auth.login( your-credentials );                             +    global.solidFetch = auth.fetch;                                   +    const $rdf = global.$rdf = require('rdflib');                     +    const kb = $rdf.graph(); +    const fetcher = $rdf.fetcher(kb);+    await fetcher.load( some-private-url );  +}+```               ++### A Browser Example++This is a fully functional script; just change the `IdP` and `privateResource` addresses.++```html+<!DOCTYPE html><html><head><meta charset="UTF-8" />                             +    <script src="https://cdn.jsdelivr.net/npm/@inrupt/solid-client-authn-browse\+r@1.11.2/dist/solid-client-authn.bundle.js"></script>                           +    <script src="https://cdn.jsdelivr.net/npm/rdflib@2.2.6/dist/rdflib.min.js">\+</script>                                                                       +</head><body>                                                                   +    <button id="login">go</button>                                              +</body>                                                                         +<script>                                                                        +    const idp = "https://solidcommunity.net";                                   +    const privateResource = "https://jeff-zucker.solidcommunity.net/private/";  +    const auth = solidClientAuthentication;                                     +    async function main(session){                                               +        const kb = $rdf.graph();                                                +        window.solidFetcher = session.fetch;                                    +        const fetcher = $rdf.fetcher(kb)                                        +        try {                                                                   +          await fetcher.load(privateResource);                                  +          alert("Private resource successfully loaded");                        +        }                                                                       +        catch(e) { alert(e) }                                                   +    }                                                                           +    document.getElementById('login').onclick = ()=> {                           +        auth.login({                                                            +            oidcIssuer: idp,                                                    +            redirectUrl: window.location.href,                                  +            clientName: "rdflib test"                                           +        });                                                                     +    }                                                                           +    async function handleRedirectAfterLogin() {                                 +        await auth.handleIncomingRedirect();                                    +        session = auth.getDefaultSession();                                     +        if (session.info.isLoggedIn)  main(session);                            +    }                                                                           +    handleRedirectAfterLogin();                                                 +</script></html>                                                                +```+++##  Custom fetchers++Another way to specify an authenticated or alternate fetch is to do it when you create the fetcher object.  This method follows the same steps as the first method, with two exceptions: omit the line *`global.solidFetch = auth.fetch`*; and instead of the line *`const fetcher = $rdf.fetcher(kb)`* use :+```javascript+const fetcher = $rdf.fetcher(kb,{fetch:auth.fetch.bind(auth)});+```+Doing things this way avoids using global variables, but also means that the changes to fetch need to be added every time you create a new fetcher object.

Yes you are right. I was fully wrong. Fetcher do not default to current fetch.

jeff-zucker

comment created time in 4 days

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentlinkeddata/rdflib.js

Create alternate-fetches.md

+# Using authenticated and alternate fetches in rdflib++By default, `rdflib`'s fetcher uses `cross-fetch.fetch()` to preform reads and writes.  This is a plain `fetch`, similar to `wget` or `curl`, that does not carry any authentication information.  To use `rdflib` with private Solid data that requires authentication, the user or app needs to pass a different fetch method to `rdflib`.  This approach is also useful if you have created your own fetch, such as against Dropbox or a database.                                                                       ++## The solidFetch variable                                                ++To use an authenticated or alternate fetch with `rdflib`++1. Load the authentication library.+2. Use it to log in to your identity provider.+3a. Set the `global.solidFetch` (or `window.solidFetch` in a browser) equal to the auth library's fetch method.+3b. OR see below to create a custom fetcher+4. Load and use `rdflib`.  All fetches will be authenticated.++_**Important Note:** Prior to `rdflib` version `2.2.9`, this variable was named `solidFetcher`, so use that with older `rdflib`s.  Going forward, please use `solidFetch`._++### A CLI (out-of-browser) Example++```javascript                                                                   +async function test() {+    const auth = new (require("solid-node-client").SolidNodeClient)();+    await auth.login( your-credentials );                             +    global.solidFetch = auth.fetch;                                   +    const $rdf = global.$rdf = require('rdflib');                     +    const kb = $rdf.graph(); +    const fetcher = $rdf.fetcher(kb);+    await fetcher.load( some-private-url );  +}+```               ++### A Browser Example++This is a fully functional script; just change the `IdP` and `privateResource` addresses.++```html+<!DOCTYPE html><html><head><meta charset="UTF-8" />                             +    <script src="https://cdn.jsdelivr.net/npm/@inrupt/solid-client-authn-browse\+r@1.11.2/dist/solid-client-authn.bundle.js"></script>                           +    <script src="https://cdn.jsdelivr.net/npm/rdflib@2.2.6/dist/rdflib.min.js">\+</script>                                                                       +</head><body>                                                                   +    <button id="login">go</button>                                              +</body>                                                                         +<script>                                                                        +    const idp = "https://solidcommunity.net";                                   +    const privateResource = "https://jeff-zucker.solidcommunity.net/private/";  +    const auth = solidClientAuthentication;                                     +    async function main(session){                                               +        const kb = $rdf.graph();                                                +        window.solidFetcher = session.fetch;                                    +        const fetcher = $rdf.fetcher(kb)                                        +        try {                                                                   +          await fetcher.load(privateResource);                                  +          alert("Private resource successfully loaded");                        +        }                                                                       +        catch(e) { alert(e) }                                                   +    }                                                                           +    document.getElementById('login').onclick = ()=> {                           +        auth.login({                                                            +            oidcIssuer: idp,                                                    +            redirectUrl: window.location.href,                                  +            clientName: "rdflib test"                                           +        });                                                                     +    }                                                                           +    async function handleRedirectAfterLogin() {                                 +        await auth.handleIncomingRedirect();                                    +        session = auth.getDefaultSession();                                     +        if (session.info.isLoggedIn)  main(session);                            +    }                                                                           +    handleRedirectAfterLogin();                                                 +</script></html>                                                                +```+++##  Custom fetchers++Another way to specify an authenticated or alternate fetch is to do it when you create the fetcher object.  This method follows the same steps as the first method, with two exceptions: omit the line *`global.solidFetch = auth.fetch`*; and instead of the line *`const fetcher = $rdf.fetcher(kb)`* use :+```javascript+const fetcher = $rdf.fetcher(kb,{fetch:auth.fetch.bind(auth)});+```+Doing things this way avoids using global variables, but also means that the changes to fetch need to be added every time you create a new fetcher object.

If I am correct in this, it is really important that within solidOS, if we need to create a new fetcher, we grab the _fetch from the existing fetch method in case the user has over-ridden it.

jeff-zucker

comment created time in 4 days

Pull request review commentlinkeddata/rdflib.js

Create alternate-fetches.md

+# Using authenticated and alternate fetches in rdflib++By default, `rdflib`'s fetcher uses `cross-fetch.fetch()` to preform reads and writes.  This is a plain `fetch`, similar to `wget` or `curl`, that does not carry any authentication information.  To use `rdflib` with private Solid data that requires authentication, the user or app needs to pass a different fetch method to `rdflib`.  This approach is also useful if you have created your own fetch, such as against Dropbox or a database.                                                                       ++## The solidFetch variable                                                ++To use an authenticated or alternate fetch with `rdflib`++1. Load the authentication library.+2. Use it to log in to your identity provider.+3a. Set the `global.solidFetch` (or `window.solidFetch` in a browser) equal to the auth library's fetch method.+3b. OR see below to create a custom fetcher+4. Load and use `rdflib`.  All fetches will be authenticated.++_**Important Note:** Prior to `rdflib` version `2.2.9`, this variable was named `solidFetcher`, so use that with older `rdflib`s.  Going forward, please use `solidFetch`._++### A CLI (out-of-browser) Example++```javascript                                                                   +async function test() {+    const auth = new (require("solid-node-client").SolidNodeClient)();+    await auth.login( your-credentials );                             +    global.solidFetch = auth.fetch;                                   +    const $rdf = global.$rdf = require('rdflib');                     +    const kb = $rdf.graph(); +    const fetcher = $rdf.fetcher(kb);+    await fetcher.load( some-private-url );  +}+```               ++### A Browser Example++This is a fully functional script; just change the `IdP` and `privateResource` addresses.++```html+<!DOCTYPE html><html><head><meta charset="UTF-8" />                             +    <script src="https://cdn.jsdelivr.net/npm/@inrupt/solid-client-authn-browse\+r@1.11.2/dist/solid-client-authn.bundle.js"></script>                           +    <script src="https://cdn.jsdelivr.net/npm/rdflib@2.2.6/dist/rdflib.min.js">\+</script>                                                                       +</head><body>                                                                   +    <button id="login">go</button>                                              +</body>                                                                         +<script>                                                                        +    const idp = "https://solidcommunity.net";                                   +    const privateResource = "https://jeff-zucker.solidcommunity.net/private/";  +    const auth = solidClientAuthentication;                                     +    async function main(session){                                               +        const kb = $rdf.graph();                                                +        window.solidFetcher = session.fetch;                                    +        const fetcher = $rdf.fetcher(kb)                                        +        try {                                                                   +          await fetcher.load(privateResource);                                  +          alert("Private resource successfully loaded");                        +        }                                                                       +        catch(e) { alert(e) }                                                   +    }                                                                           +    document.getElementById('login').onclick = ()=> {                           +        auth.login({                                                            +            oidcIssuer: idp,                                                    +            redirectUrl: window.location.href,                                  +            clientName: "rdflib test"                                           +        });                                                                     +    }                                                                           +    async function handleRedirectAfterLogin() {                                 +        await auth.handleIncomingRedirect();                                    +        session = auth.getDefaultSession();                                     +        if (session.info.isLoggedIn)  main(session);                            +    }                                                                           +    handleRedirectAfterLogin();                                                 +</script></html>                                                                +```+++##  Custom fetchers++Another way to specify an authenticated or alternate fetch is to do it when you create the fetcher object.  This method follows the same steps as the first method, with two exceptions: omit the line *`global.solidFetch = auth.fetch`*; and instead of the line *`const fetcher = $rdf.fetcher(kb)`* use :+```javascript+const fetcher = $rdf.fetcher(kb,{fetch:auth.fetch.bind(auth)});+```+Doing things this way avoids using global variables, but also means that the changes to fetch need to be added every time you create a new fetcher object.

This succeeds on the first fetch and fails 401 on the second :

const auth = new (require("solid-node-client").SolidNodeClient)();              
const $rdf = global.$rdf = require('rdflib');                                   
const privateResource = "https://jeff-zucker.solidcommunity.net/private/";      
async function test() {                                                         
    await auth.login();                                                         
    const kb = $rdf.graph();                                                    
    const fetcher1 = $rdf.fetcher(kb,{fetch:auth.fetch.bind(auth)});            
    try {                                                                       
       await fetcher1.load(privateResource);                                    
       console.log("Private resource successfully loaded");                     
     }                                                                          
    catch(e) { console.log(e) }                                                 
    const fetcher2 = $rdf.fetcher(kb);                                          
    try {                                                                       
       await fetcher2.load(privateResource);                                    
       console.log("Private resource successfully loaded");                     
     }                                                                          
    catch(e) { console.log(e) }                                                 
}                                                                               
test();    
jeff-zucker

comment created time in 4 days

PullRequestReviewEvent

Pull request review commentlinkeddata/rdflib.js

Create alternate-fetches.md

+# Using authenticated and alternate fetches in rdflib++By default, `rdflib`'s fetcher uses `cross-fetch.fetch()` to preform reads and writes.  This is a plain `fetch`, similar to `wget` or `curl`, that does not carry any authentication information.  To use `rdflib` with private Solid data that requires authentication, the user or app needs to pass a different fetch method to `rdflib`.  This approach is also useful if you have created your own fetch, such as against Dropbox or a database.                                                                       ++## The solidFetch variable                                                ++To use an authenticated or alternate fetch with `rdflib`++1. Load the authentication library.+2. Use it to log in to your identity provider.+3a. Set the `global.solidFetch` (or `window.solidFetch` in a browser) equal to the auth library's fetch method.+3b. OR see below to create a custom fetcher+4. Load and use `rdflib`.  All fetches will be authenticated.++_**Important Note:** Prior to `rdflib` version `2.2.9`, this variable was named `solidFetcher`, so use that with older `rdflib`s.  Going forward, please use `solidFetch`._++### A CLI (out-of-browser) Example++```javascript                                                                   +async function test() {+    const auth = new (require("solid-node-client").SolidNodeClient)();+    await auth.login( your-credentials );                             +    global.solidFetch = auth.fetch;                                   +    const $rdf = global.$rdf = require('rdflib');                     +    const kb = $rdf.graph(); +    const fetcher = $rdf.fetcher(kb);+    await fetcher.load( some-private-url );  +}+```               ++### A Browser Example++This is a fully functional script; just change the `IdP` and `privateResource` addresses.++```html+<!DOCTYPE html><html><head><meta charset="UTF-8" />                             +    <script src="https://cdn.jsdelivr.net/npm/@inrupt/solid-client-authn-browse\+r@1.11.2/dist/solid-client-authn.bundle.js"></script>                           +    <script src="https://cdn.jsdelivr.net/npm/rdflib@2.2.6/dist/rdflib.min.js">\+</script>                                                                       +</head><body>                                                                   +    <button id="login">go</button>                                              +</body>                                                                         +<script>                                                                        +    const idp = "https://solidcommunity.net";                                   +    const privateResource = "https://jeff-zucker.solidcommunity.net/private/";  +    const auth = solidClientAuthentication;                                     +    async function main(session){                                               +        const kb = $rdf.graph();                                                +        window.solidFetcher = session.fetch;                                    +        const fetcher = $rdf.fetcher(kb)                                        +        try {                                                                   +          await fetcher.load(privateResource);                                  +          alert("Private resource successfully loaded");                        +        }                                                                       +        catch(e) { alert(e) }                                                   +    }                                                                           +    document.getElementById('login').onclick = ()=> {                           +        auth.login({                                                            +            oidcIssuer: idp,                                                    +            redirectUrl: window.location.href,                                  +            clientName: "rdflib test"                                           +        });                                                                     +    }                                                                           +    async function handleRedirectAfterLogin() {                                 +        await auth.handleIncomingRedirect();                                    +        session = auth.getDefaultSession();                                     +        if (session.info.isLoggedIn)  main(session);                            +    }                                                                           +    handleRedirectAfterLogin();                                                 +</script></html>                                                                +```+++##  Custom fetchers++Another way to specify an authenticated or alternate fetch is to do it when you create the fetcher object.  This method follows the same steps as the first method, with two exceptions: omit the line *`global.solidFetch = auth.fetch`*; and instead of the line *`const fetcher = $rdf.fetcher(kb)`* use :+```javascript+const fetcher = $rdf.fetcher(kb,{fetch:auth.fetch.bind(auth)});+```+Doing things this way avoids using global variables, but also means that the changes to fetch need to be added every time you create a new fetcher object.

@bourgeoa - I believe you are wrong. I tested and could not make it work. If you create a fetcher with fetcher = $rdf.fetcher(kb) without options it will be an unauthenticted fetch even if you previously created a fetcher that was authenticated. If you have a test case where the authentication is preserved across creation of fetchers, please post it.

jeff-zucker

comment created time in 4 days

PullRequestReviewEvent

Pull request review commentlinkeddata/rdflib.js

Create alternate-fetches.md

+# Using authenticated and alternate fetches in rdflib++By default, `rdflib`'s fetcher uses `cross-fetch.fetch()` to preform reads and writes.  This is a plain `fetch`, similar to `wget` or `curl`, that does not carry any authentication information.  To use `rdflib` with private Solid data that requires authentication, the user or app needs to pass a different fetch method to `rdflib`.  This approach is also useful if you have created your own fetch, such as against Dropbox or a database.                                                                       ++## The solidFetch variable                                                ++To use an authenticated or alternate fetch with `rdflib`++1. Load the authentication library.+2. Use it to log in to your identity provider.+3a. Set the `global.solidFetch` (or `window.solidFetch` in a browser) equal to the auth library's fetch method.+3b. OR see below to create a custom fetcher+4. Load and use `rdflib`.  All fetches will be authenticated.++_**Important Note:** Prior to `rdflib` version `2.2.9`, this variable was named `solidFetcher`, so use that with older `rdflib`s.  Going forward, please use `solidFetch`._++### A CLI (out-of-browser) Example++```javascript                                                                   +async function test() {+    const auth = new (require("solid-node-client").SolidNodeClient)();+    await auth.login( your-credentials );                             +    global.solidFetch = auth.fetch;                                   +    const $rdf = global.$rdf = require('rdflib');                     +    const kb = $rdf.graph(); +    const fetcher = $rdf.fetcher(kb);+    await fetcher.load( some-private-url );  +}+```               ++### A Browser Example++This is a fully functional script; just change the `IdP` and `privateResource` addresses.++```html+<!DOCTYPE html><html><head><meta charset="UTF-8" />                             +    <script src="https://cdn.jsdelivr.net/npm/@inrupt/solid-client-authn-browse\+r@1.11.2/dist/solid-client-authn.bundle.js"></script>                           +    <script src="https://cdn.jsdelivr.net/npm/rdflib@2.2.6/dist/rdflib.min.js">\+</script>                                                                       +</head><body>                                                                   +    <button id="login">go</button>                                              +</body>                                                                         +<script>                                                                        +    const idp = "https://solidcommunity.net";                                   +    const privateResource = "https://jeff-zucker.solidcommunity.net/private/";  +    const auth = solidClientAuthentication;                                     +    async function main(session){                                               +        const kb = $rdf.graph();                                                +        window.solidFetcher = session.fetch;                                    +        const fetcher = $rdf.fetcher(kb)                                        +        try {                                                                   +          await fetcher.load(privateResource);                                  +          alert("Private resource successfully loaded");                        +        }                                                                       +        catch(e) { alert(e) }                                                   +    }                                                                           +    document.getElementById('login').onclick = ()=> {                           +        auth.login({                                                            +            oidcIssuer: idp,                                                    +            redirectUrl: window.location.href,                                  +            clientName: "rdflib test"                                           +        });                                                                     +    }                                                                           +    async function handleRedirectAfterLogin() {                                 +        await auth.handleIncomingRedirect();                                    +        session = auth.getDefaultSession();                                     +        if (session.info.isLoggedIn)  main(session);                            +    }                                                                           +    handleRedirectAfterLogin();                                                 +</script></html>                                                                +```+++##  Custom fetchers++Another way to specify an authenticated or alternate fetch is to do it when you create the fetcher object.  This method follows the same steps as the first method, with two exceptions: omit the line *`global.solidFetch = auth.fetch`*; and instead of the line *`const fetcher = $rdf.fetcher(kb)`* use :+```javascript+const fetcher = $rdf.fetcher(kb,{fetch:auth.fetch.bind(auth)});+```+Doing things this way avoids using global variables, but also means that the changes to fetch need to be added every time you create a new fetcher object.

Is this true ? My understanding was that the fetch was installed as $rdf.fetch so was kept if you do not create a new rdf object. It is the way it is used in SolidOS. You can create new store $rdf.graph() or $rdf.fetcher() and keep the same $rdf.fetch.

jeff-zucker

comment created time in 4 days

PullRequestReviewEvent

push eventlinkeddata/rdflib.js

jeff-zucker

commit sha 8b1f73cc2b46eb07b94c379da3da6b564afb93fb

added text on global vars

view details

push time in 4 days

pull request commentlinkeddata/rdflib.js

Create alternate-fetches.md

@jeff-zucker

  • On your branch jeff-zucker-alternate-fetches you should git pull locally.
  • or something like git pull origin jeff-zucker-alternate-fetches

Then make the new changes

jeff-zucker

comment created time in 4 days

pull request commentlinkeddata/rdflib.js

Create alternate-fetches.md

I was with the idea that best practice was to avoid using global in javascript. Why not indicate directly in 3. that you could either use global/window or $rdf.fetcher ?

Yes, that's probably a good idea. I don't know how to make that change without losing the changes you and Ted have made. If I edit the original, it doesn't have any of your changes.

jeff-zucker

comment created time in 4 days

push eventlinkeddata/rdflib.js

Jeff Zucker

commit sha ca454939325dd3c5dc128a2486c61f5260f197e5

Update Documentation/alternate-fetches.md Co-authored-by: Alain Bourgeois <alain.bourgeois10@gmail.com>

view details

push time in 4 days

pull request commentlinkeddata/rdflib.js

Create alternate-fetches.md

I was with the idea that best practice was to avoid using global in javascript. Why not indicate directly in 2. that you could either use global/window or $rdf.fetcher ?

jeff-zucker

comment created time in 4 days

Pull request review commentlinkeddata/rdflib.js

Create alternate-fetches.md

+# Using authenticated and alternate fetches in rdflib++By default, `rdflib`'s fetcher uses `cross-fetch.fetch()` to preform reads and writes.  This is a plain `fetch`, similar to `wget` or `curl`, that does not carry any authentication information.  To use `rdflib` with private Solid data that requires authentication, the user or app needs to pass a different fetch method to `rdflib`.  This approach is also useful if you have created your own fetch, such as against Dropbox or a database.                                                                       ++## The solidFetch variable                                                ++To to use an authenticated or alternate fetch with `rdflib`
To use an authenticated or alternate fetch with `rdflib`
jeff-zucker

comment created time in 4 days

PullRequestReviewEvent

push eventlinkeddata/rdflib.js

Jeff Zucker

commit sha 0e27fde7621f2d55b1b9cb5002f12c98e0bbdda7

Update Documentation/alternate-fetches.md Co-authored-by: Ted Thibodeau Jr <tthibodeau@openlinksw.com>

view details

push time in 5 days

more