-
Notifications
You must be signed in to change notification settings - Fork 41
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
Provide the ability to add authorization headers to SPARQL endpoint in react #517
Comments
See #448 - no solution yet, but we will raise the criticity of this issue |
I cannot provide my SPARQL endpoint myself but I may come back to you if i can. I find a workaround for my situtation: components/sparnatural.tsx <spar-natural
ref={sparnaturalRef}
src={sparnaturalConfigRoute}
endpoint={`/api/executeSparnaturalQuery?authorization=${getAccessToken()}`}
lang="fr"
//queryLang="fr"
distinct="true"
limit="10"
debug="true"
></spar-natural> with my endpoint being in nextJS and not requiring an authorization header when called from my component I can then,
pages/api/executeSparnaturalQuery.ts const response = await (await fetch(request.url, {
method: request.method,
headers: {
"Authorization": `Bearer ${params.token}`,
}
})).json();
res.status(200).json({error: false, message: 'Query response OK', results: {"bindings": response}}) |
Latest commit should allow you to set custom headers that will be passed in requests from list, autocomplete and tree widgets: Set it like so:
Would you be able to give it a try ? |
Could you provide a way of testing sparnatural locally ? I was using sparnatural 8.4.0 and tried to clone the project then add it to my react dependencies in package.json : "devDependencies": { but my application can't find modules the same way it used to do using the packaged version of sparnatural. Regardless, thank you for your quick answer and implementation, that is really appreciated |
|
Hello, I just find out that my workaround is forcing my component to reload, because either" src" to get config or "endpoint" to use widgets, is being reloaded when my token changes. |
Hello, last release worked great but I think there is still something to work on about this header thingy, when creating a component in react <spar-natural
ref={sparnaturalRef}
src={`<config/endpoint>`}
endpoint={`<api/endpoint>`}
lang="fr"
//queryLang="fr"
distinct="true"
limit="-1"
debug="false"
></spar-natural> Since src is calling the config/endpoint at initialization, the code bellow is not yet executed sparnatural.addEventListener(
"init",
(event: SparnaturalEvent) => {
sparnatural.headers = {
"Authorization": `Bearer ${getAccessToken()}`
}
}
); making it work only for api call on endpoint but not when getting the sparnatural configuration, I think the expected behavior would be for the configuration to be able to use the header once set |
Ha yes, you are absolutely right, headers are not passed on the loading of the configuration itself. I will open a separate issue for this. |
Hello, I am trying to integrate Sparnatural in a react application with NextJS and my endpoint requires a private token, it is usually registred like this :
I want to be able to access my endpoint with this kind of configuration :
I want to use the given "endpoint" with headers in a way that would enable me to pass my authorization header.
I have not found in the documentation or in any topic related issues, something that would work as a workaround for my problem.
Is there anything I can do, thank you in advance
I use sparnatural 8.4.0
The text was updated successfully, but these errors were encountered: