HTTP Basic Authentication


On this page

    Via HTTP Basic Authentication one can include username and password credentials in HTTP requests. If you want to query such protected resources, you can include this authentication information for all HTTP requests, or only for requests to specific sources.

    Authentication on the command line

    Via the command line, username and password can be included in the URL as follows:

    $ comunica-sparql https://username:password@example.org/page \
      "SELECT * WHERE { ?s ?p ?o }"
    

    Authentication in an application

    When using Comunica SPARQL in an application, authentication information can be set using the httpAuth context entry:

    Enabling basic authentication for all HTTP requests:

    const bindingsStream = await myEngine.queryBindings(`SELECT * WHERE { ?s ?p ?o }`, {
      sources: ['http://fragments.dbpedia.org/2015/en'],
      httpAuth: 'username:password',
    });
    

    Enabling basic authentication for a specific source:

    const bindingsStream = await myEngine.queryBindings(`SELECT * WHERE { ?s ?p ?o }`, {
      sources: ['http://username:password@example.org/page'],
    });