Skip to content

Support for Bearer tokensΒ #673

@redmer

Description

@redmer

I want to use Trifid with a SPARQL endpoint that uses Bearer tokens for authentication.

The suggested solution to #147 was to use fetchOptions.headers, but I can't seem to get that working anymore. And indeed, a cursory view of the code in this monorepo seems to confirm that sparql-proxy doesn't seem to be able to use generic overrides. I've tried it with the following config.yaml, adapted from the default config.yaml (trying all different places for the (fetchOptions.)headers):

Details

server:
  logLevel: debug

globals:
  datasetBaseUrl: env:DATASET_BASE_URL
  endpoints:
    default:
      url: /query
  config:
    headers:
      Authorization: env:SPARQL_ENDPOINT_TOKEN
    fetchOptions:
      headers:
        Authorization: env:SPARQL_ENDPOINT_TOKEN
  headers:
    Authorization: env:SPARQL_ENDPOINT_TOKEN
  fetchOptions:
    headers:
      Authorization: env:SPARQL_ENDPOINT_TOKEN

plugins:
  static-assets:
    module: trifid-core/plugins/static.js
    order: 0
    paths: /static-assets
    config:
      directory: file:static

  welcome:
    module: trifid-core/plugins/view.js
    paths: /
    methods: GET
    config:
      path: file:welcome.hbs

  entity-renderer:
    module: "@zazuko/trifid-entity-renderer"
    config:
      followRedirects: true
      labelLoader:
        chunkSize: 30
        concurrency: 2
        timeout: 4000

  yasgui:
    module: trifid-plugin-yasgui
    paths:
      - /sparql
      - /sparql/

  graph-explorer:
    module: trifid-plugin-graph-explorer
    paths:
      - /graph-explorer
      - /graph-explorer/
    config:
      dataLabelProperty: <http://www.w3.org/2004/02/skos/core#prefLabel>
      schemaLabelProperty: <http://www.w3.org/2004/02/skos/core#prefLabel>
      language: nl-NL
      languages:
        - code: nl-NL
          label: Dutch
        - code: nl
          label: Nederlands

  spex:
    module: trifid-plugin-spex
    paths:
      - /spex
      - /spex/

  sparql-proxy:
    module: "@zazuko/trifid-plugin-sparql-proxy"
    paths: /query
    config:
      allowRewriteToggle: true
      rewrite: false
      rewriteQuery: true
      rewriteResults: true
      endpointUrl: env:SPARQL_ENDPOINT_URL
      formats:
        ttl: "text/turtle"
        jsonld: "application/ld+json"
        xml: "application/rdf+xml"
        nt: "application/n-triples"
        trig: "application/trig"
        csv: "text/csv"
      headers:
        Authorization: env:SPARQL_ENDPOINT_TOKEN
      fetchOptions:
        headers:
          Authorization: env:SPARQL_ENDPOINT_TOKEN

and calling it with

docker run \
	-v $(PWD):/data \
	-e TRIFID_CONFIG=/data/config.yaml \
	-e SPARQL_ENDPOINT_URL=https://api.datasets.example.org/datasets/redacted/redacted/sparql \
	-e DATASET_BASE_URL=https://data.example.org/ \
	-e SPARQL_ENDPOINT_TOKEN="Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.redacted.redacted" \
	--rm -it -p 8080:8080 ghcr.io/zazuko/trifid

This configuration works as expected with a public SPARQL_ENDPOINT_URL, that requires no valid Authorization: Bearer eyJ....

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions