Custom esri token service (#1813)

* Added ability for self-hosted token service to be specified.

* Update documentation to show the available parameters

* Update pygeoapi/provider/esri.py

Co-authored-by: Benjamin Webb <40066515+webb-ben@users.noreply.github.com>

* Update pygeoapi/provider/esri.py

Co-authored-by: Benjamin Webb <40066515+webb-ben@users.noreply.github.com>

* Update pygeoapi/provider/esri.py

Co-authored-by: Benjamin Webb <40066515+webb-ben@users.noreply.github.com>

* Update pygeoapi/provider/esri.py

Co-authored-by: Benjamin Webb <40066515+webb-ben@users.noreply.github.com>

* Update pygeoapi/provider/esri.py

* Update ogcapi-features.rst

---------

Co-authored-by: Benjamin Webb <40066515+webb-ben@users.noreply.github.com>
Co-authored-by: Tom Kralidis <tomkralidis@gmail.com>
This commit is contained in:
Colin Henderson
2024-10-01 15:53:39 +01:00
committed by GitHub
parent d240a8210e
commit e736fa3b2f
2 changed files with 27 additions and 5 deletions
@@ -145,7 +145,11 @@ To publish an ESRI `Feature Service`_ or `Map Service`_ specify the URL for the
* ``id_field`` will often be ``OBJECTID``, ``objectid``, or ``FID``.
* If the map or feature service is not shared publicly, the ``username`` and ``password`` fields can be set in the
configuration to authenticate into the service.
configuration to authenticate to the service.
* If the map or feature service is self-hosted and not shared publicly, the ``token_service`` and optional ``referer`` fields
can be set in the configuration to authenticate to the service.
To publish from an ArcGIS online hosted service:
.. code-block:: yaml
@@ -158,6 +162,24 @@ To publish an ESRI `Feature Service`_ or `Map Service`_ specify the URL for the
crs: 4326 # Optional crs (default is EPSG:4326)
username: username # Optional ArcGIS username
password: password # Optional ArcGIS password
token_service: https://your.server.com/arcgis/sharing/rest/generateToken # optional URL to your generateToken service
referer: https://your.server.com # optional referer, defaults to https://www.arcgis.com if not set
To publish from a self-hosted service that is not publicly accessible, the ``token_service`` field is required:
.. code-block:: yaml
providers:
- type: feature
name: ESRI
data: https://your.server.com/arcgis/rest/services/your-layer/MapServer/0
id_field: objectid
time_field: date_in_your_device_time_zone # Optional time field
crs: 4326 # Optional crs (default is EPSG:4326)
username: username # Optional ArcGIS username
password: password # Optional ArcGIS password
token_service: https://your.server.com/arcgis/sharing/rest/generateToken # Optional url to your generateToken service
referer: https://your.server.com # Optional referer, defaults to https://www.arcgis.com if not set
GeoJSON
^^^^^^^
+4 -4
View File
@@ -62,8 +62,9 @@ class ESRIServiceProvider(BaseProvider):
self.crs = provider_def.get('crs', '4326')
self.username = provider_def.get('username')
self.password = provider_def.get('password')
self.token_url = provider_def.get('token_service', ARCGIS_URL)
self.token_referer = provider_def.get('referer', GENERATE_TOKEN_URL)
self.token = None
self.session = Session()
self.login()
@@ -194,16 +195,15 @@ class ESRIServiceProvider(BaseProvider):
msg = 'Missing ESRI login information, not setting token'
LOGGER.debug(msg)
return
params = {
'f': 'pjson',
'username': self.username,
'password': self.password,
'referer': ARCGIS_URL
'referer': self.token_referer
}
LOGGER.debug('Logging in')
with self.session.post(GENERATE_TOKEN_URL, data=params) as r:
with self.session.post(self.token_url, data=params) as r:
self.token = r.json().get('token')
# https://enterprise.arcgis.com/en/server/latest/administer/windows/about-arcgis-tokens.htm
self.session.headers.update({