Calling EDG APIs with Basic Auth from Python

57 views
Skip to first unread message

Nick Sacoman

unread,
Jun 21, 2023, 10:14:19 AM6/21/23
to TopBraid Suite Users
I currently am testing one of the API endpoints: specifically the exportRDFFile endpoint for a taxonomy. I've read the documentation and have configured BasicAuth with my Python request. I'm running into an error I will post below along with my code stub. I've tried this with all user accounts to no avail (it is on my localhost, I am the admin for more clarity). I would appreciate some pointers to get this cleared up.

Code stub (Python3):
`session = requests.Session()`
`session.headers.update({"Connection": "Keep-alive"})`
`res = session.get("http://localhost:8083/tbl/service/{taxonomy_name}/tbs/exportRDFFile?format=json-ld", auth=HTTPBasicAuth("user", "password")).text`

Response (res):
"Cannot invoke org.topbraid.auth.TBUser.canUpdate(org.topbraid.auth.Asset) because the return value of org.topbraid.auth.user.TBUserFactory.getUser() is null."

Richard Cyganiak

unread,
Jun 21, 2023, 10:58:14 AM6/21/23
to topbrai...@googlegroups.com
Hi Nick,

Is this with EDG Studio or is it with edg.war on Tomcat? Which version of EDG?

Has EDG been configured for HTTP Basic Authentication? In other words, when logging in to EDG in the browser, is the login form a browser popup dialog, as opposed to some kind of web form?

The service URL looks a bit off. The {taxonomy_name} part should be the ID of the asset collection, without { } around it. You can find the URL by navigating to your asset collection in EDG, then going to the Reports tab, selecting Web Services Swagger UI, and finding exportRDFFile in the list.

Hope that helps,
Richard




--
The topics of this mailing list include TopBraid EDG and related technologies such as SHACL.
To post to this group, send email to topbrai...@googlegroups.com
---
You received this message because you are subscribed to the Google Groups "TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to topbraid-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/topbraid-users/d1702a77-1f11-4b86-883e-fe083954d627n%40googlegroups.com.

Pat Doyle

unread,
Jun 21, 2023, 11:13:23 AM6/21/23
to topbrai...@googlegroups.com
Here's an extract from a script I've written to export via python with basic auth in the past(it may not work perfectly as-is since I pulled it out of a much larger script):

import json
import requests
from zipfile import ZipFile
from zipfile import ZIP_DEFLATED
from http.client import HTTPConnection
user = "admin"
password = "test"
editorBaseURL = "http://localhost:8083/tbl/";
editorSession = requests.session() 
exportURL = editorBaseURL + "service/" + graphName + "/tbs/exportRDFFile?format=turtle"
ttlFile = editorSession.get(exportURL, auth=(user, password));

Hope it helps,

Pat 

Nick Sacoman

unread,
Jun 21, 2023, 11:16:33 AM6/21/23
to TopBraid Suite Users
Hi there,

Thanks so much for the quick response! Apologies for missing some key information - I'm using EDG Studio. When I launch EDG Studio from localhost, I'm automatically signed in as administrator. I'm a bit new to the tool, so I have not configured the instance for Basic Authentication - are there documentation references for doing so?

Also - I did not specify, but the {taxonomy name} was a placeholder, I did format that portion of the API URL as the Swagger UI instructed me to do.

Thanks,
Nick

Nick Sacoman

unread,
Jun 21, 2023, 11:33:48 AM6/21/23
to TopBraid Suite Users
This is also EDG Studio version 7.3.1

Richard Cyganiak

unread,
Jun 21, 2023, 12:57:05 PM6/21/23
to topbrai...@googlegroups.com
Hi Nick,

By default, authentication is disabled in EDG Studio. When doing API requests in this mode, a cookie with the user name, e.g., “username=Administrator” should be included with every request.

The EDG Studio documentation doesn’t have anything on configuring authentication. This topic is covered in the docs for the full EDG server product, but not all of that is applicable to Studio.

To enable basic authentication, here is what works for me.

First I create a file called setup.basic-auth.properties in the EDG Studio directory. The file contains:

authMethod=basic
securityRoles=administrator,manager,user,viewer

(If you want to know what else can be configured in this file, launch Studio in the usual way and navigate to http://localhost:8083/assets/edg-setup/edg-setup.properties to get a template. A few of the options won’t work in EDG Studio.)

Now I edit the file conf/users.xml to define my users, passwords, and roles. Note that all users and roles are commented out initially. The <role> elements must match the list of securityRoles defined earlier in the setup file.

Now I launch EDG Studio with the shell command: edg -s setup.basic-auth.properties

EDG should launch with basic authentication enabled. The browser should pop up a dialog asking for username and password. Any of the credentials configured in users.xml should work.

Initially, all roles will get administrator rights. To change that, I log in and go to Server Administration > Rights Management, then select my administrator role, and add AdministratorGroup to it. Then I select ANY_ROLE and remove AdministratorGroup from it. Now, only members of the administrator role will be able to access Server Administration etc.

Now I can use incognito windows to log in as different users.

Hope that helps,
Richard





Nick Sacoman

unread,
Jun 21, 2023, 1:40:34 PM6/21/23
to TopBraid Suite Users
Hi Richard,

This is incredibly helpful! I'll give these steps and information a shot with my local setup and see if I can work it out. Thank you all who reached out, it's very appreciated!

Nick

Nick Sacoman

unread,
Jun 21, 2023, 1:55:13 PM6/21/23
to TopBraid Suite Users
Circling back around to say that the Cookie got me back results! Y'all are a super helpful group, thanks again for solving this issue!!
Reply all
Reply to author
Forward
0 new messages