简体   繁体   中英

How to make a call with dotNetRDF to an RDF datasource with a bearer token?

I am loading an RDF document, using the dotNetRDF library by doing the following:

var g = new Graph();
UriLoader.Load(g, new Uri("https://myuri"));

If I load from a protected datasource, requiring a bearer token for authentication, how should I do? including the bearer token in my URI? like this:

var g = new Graph();
UriLoader.Load(g, new Uri("https://myuri?_bearer=MYTOKEN"));

Would that be enough?

Same question on how to pass a bearer token to a remote SPARQL query

Thank you

For UriLoader you can't if the service you are requesting from requires the token in a HTTP Header. There is no exposed capability to modify the HTTP request sent in that API.

Note that UriLoader is ultimately just a convenience wrapper around URI retrieval via HttpWebRequest so you can always make a HTTP request manually with whatever extra headers you need and hand the response stream onto a IRdfReader / IRdfHandler as needed.

If the remote service allows specifying the Token directly in the URI then that should work via UriLoader but that will depend on the remote service.

If your data is accessible via a SPARQL Graph Store Protocol endpoint then you could extend SparqlHttpProtocolConnector and override the ApplyRequestOptions(HttpWebRequest) method to specify desired options such as custom Authorization header which would reduce the additional work you need to do.

Historical aside - Much of the early core of dotNetRDF was written prior to the introduction of the Bearer auth scheme and at a time when most semantic data sources were published freely on the web without any authentication needed. Obviously since then HTTP standards have moved on and the idea of the private knowledge graph has become popularised meaning there are more ways to authenticate and more need for authentication.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM