How to use the solid-auth-client.fetch function in solid-auth-client

To help you get started, we’ve selected a few solid-auth-client examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github solid / query-ldflex / src / ComunicaUpdateEngine.js View on Github external
const next = async () => {
      if (done)
        return { done };
      done = true;

      // Find the document to update
      const sources = await (source ? this.toComunicaSources(source) : this._sources);
      if (!sources || sources.length !== 1)
        throw new Error('Can only update a single source.');
      const [{ value: document }] = sources;
      if (!/^https?:\/\//.test(document))
        throw new Error('Can only update an HTTP(s) document.');

      // Send authenticated PATCH request to the document
      const { ok, status, statusText } = await auth.fetch(document, {
        method: 'PATCH',
        headers: {
          'Content-Type': 'application/sparql-update',
        },
        body: sparql,
      });

      // Error if the server response was not ok
      if (!ok)
        throw new Error(`Update query failed (${status}): ${statusText}`);

      // Clear stale cached versions of the document
      await this.clearCache(document);

      return { value: createBindings({ ok }) };
    };
github Eximua / solid-ipfs / src / solid-file-client.js View on Github external
fetch: async function(url,request){
    var res = await solid.fetch(url,request).catch(err => {
       this.err = err; return false 
    })
    if(!res.ok) { 
        this.err = res.status + " ("+res.statusText+")"
        return false 
    }
    var txt = await res.text().catch(err => {
       this.err = err; return false 
    })
    return({value:txt})
},
/* SESSION MANAGEMENT
github linkeddata / dokieli / src / fetcher.js View on Github external
function getResourceOptions (url, options = {}) {
  var _fetch = Config.User.OIDC? solidAuth.fetch : fetch;
  url = url || currentLocation()

  options.method = 'OPTIONS'

  if (!options.noCredentials) {
    options.credentials = 'include'
  }

  return _fetch(url, options)

    .then(response => {
      if (!response.ok) {  // not a 2xx level response
        let error = new Error('Error fetching resource OPTIONS: ' +
          response.status + ' ' + response.statusText)
        error.status = response.status
        error.response = response
github Eximua / solid-ipfs / src / solid-file-client.js View on Github external
fetchAndParse: async function(url,contentType){
    contentType = contentType || this.guessFileType(url)
    var res = await solid.fetch(url).catch(err=>{
        this.err=err; console.log(err); return false;
    })
    if(!res.ok) { 
        this.err = res.status + " ("+res.statusText+")"
        return false 
    }
    if( contentType==='application/json' ){
        var obj = await res.json().catch(err=>{this.err=err; return false })
        return (obj)
    }
    var txt = await res.text().catch(err=>{this.err=err; return false })
    return this.text2graph(txt,url,contentType)
},
text2graph: function(text,url,contentType){
github linkeddata / dokieli / src / fetcher.js View on Github external
function putResource (url, data, contentType, links, options = {}) {
  var _fetch = Config.User.OIDC? solidAuth.fetch : fetch;
  if (!url) {
    return Promise.reject(new Error('Cannot PUT resource - missing url'))
  }

  options.method = 'PUT'

  options.body = data

  if (!options.noCredentials) {
    options.credentials = 'include'
  }

  options.headers = options.headers || {}

  options.headers['Content-Type'] = contentType || DEFAULT_CONTENT_TYPE
github Eximua / solid-ipfs / src / solid-file-client.js View on Github external
add: async function(parentFolder,newThing,type,content) {
    var link = '; rel="type"';
    var filetype;
    if(type==='folder'){
        var link = '; rel="type"'
        filetype = "text/turtle"
    }
    var request = {
         method : 'POST',
         headers : { 'Content-Type':filetype,slug:newThing,link:link }
    }
    if(content) request.body=content
    var response = await solid.fetch( parentFolder, request )
                         .catch(err=>{this.err=err;return false})
    if(response.ok) return true
    else { 
        this.err = response.status + " ("+response.statusText+")"
        return false 
    }
},
fetch: async function(url,request){

solid-auth-client

Opaquely authenticates solid clients

MIT
Latest version published 3 years ago

Package Health Score

52 / 100
Full package analysis

Similar packages