Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Bearer tokens #673

Open
redmer opened this issue Mar 11, 2025 · 0 comments
Open

Support for Bearer tokens #673

redmer opened this issue Mar 11, 2025 · 0 comments

Comments

@redmer
Copy link

redmer commented Mar 11, 2025

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....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant