You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It's not currently possible to test Folksonomy API locally without installing Product Opener, due to authentication concerns.
To test the API using http://api.folksonomy.openfoodfacts.localhost:8888/docs Folksonomy API need that the user is identified. And the authentication is done through Product Opener. Here is the code that rules this behavior:
In folksonomy/ap.py
defget_auth_server(request: Request):
""" Get auth server URL from request We deduce it by changing part of the request base URL according to FOLKSONOMY_PREFIX and AUTH_PREFIX settings """base_url=f"{request.base_url.scheme}://{request.base_url.netloc}"# remove folksonomy prefix and add AUTH prefixbase_url=base_url.replace(settings.FOLKSONOMY_PREFIXor"", settings.AUTH_PREFIXor"")
returnbase_url# Then get_auth_server is used to build the url used by Folksonomy to request authentication:auth_url=get_auth_server(request) +"/cgi/auth.pl"
Following a config file:
# OpenFoodFacts username and password for authentication for tests only!OFF_TEST_USER='myusername'OFF_TEST_PASSWORD='mypassword'# PostgresPOSTGRES_USER=''# Leave empty if no user exists for databasePOSTGRES_PASSWORD=''# Leave empty if no password exists for userPOSTGRES_HOST=''# Change if necessaryPOSTGRES_DATABASE='folksonomy/'# for dev using a local product opener instance you can use this# base domain has to be the same (see INSTALL.md)#FOLKSONOMY_PREFIX="api.folksonomy.openfoodfacts.localhost:8888"#AUTH_PREFIX="world.openfoodfacts.localhost"
I don't understand why deduce the auth server from the current request. Why not puting the auth server in a config variable (eg. AUTH_SERVER_URL). This would allow to easily switch between cases:
testing Folksonomy API with Product Opener installed locally: AUTH_SERVER_URL="http://world.openfoodfacts.localhost"
testing Folksonomy API without Product Opener installed locally: AUTH_SERVER_URL="https://world.openfoodfacts.org"
A simple solution is to add a AUTH_SERVER_STATIC variable in envs (or in local_settings) and if it exists and is not empty, use that instead of the base_url (still do it in get_auth_server)
It's not currently possible to test Folksonomy API locally without installing Product Opener, due to authentication concerns.
To test the API using http://api.folksonomy.openfoodfacts.localhost:8888/docs Folksonomy API need that the user is identified. And the authentication is done through Product Opener. Here is the code that rules this behavior:
In folksonomy/ap.py
Following a config file:
See also instruction in install documentation.
I don't understand why deduce the auth server from the current request. Why not puting the auth server in a config variable (eg.
AUTH_SERVER_URL
). This would allow to easily switch between cases:AUTH_SERVER_URL="http://world.openfoodfacts.localhost"
AUTH_SERVER_URL="https://world.openfoodfacts.org"
AUTH_SERVER_URL="https://world.openfoodfacts.org"
The text was updated successfully, but these errors were encountered: