Skip to content

Commit

Permalink
Custom esri token service (#1813)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>

* Update pygeoapi/provider/esri.py

Co-authored-by: Benjamin Webb <[email protected]>

* Update pygeoapi/provider/esri.py

Co-authored-by: Benjamin Webb <[email protected]>

* Update pygeoapi/provider/esri.py

Co-authored-by: Benjamin Webb <[email protected]>

* Update pygeoapi/provider/esri.py

* Update ogcapi-features.rst

---------

Co-authored-by: Benjamin Webb <[email protected]>
Co-authored-by: Tom Kralidis <[email protected]>
  • Loading branch information
3 people authored Oct 1, 2024
1 parent d240a82 commit e736fa3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
24 changes: 23 additions & 1 deletion docs/source/data-publishing/ogcapi-features.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
^^^^^^^
Expand Down
8 changes: 4 additions & 4 deletions pygeoapi/provider/esri.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ def __init__(self, provider_def):
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()
Expand Down Expand Up @@ -194,16 +195,15 @@ def login(self):
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({
Expand Down

0 comments on commit e736fa3

Please sign in to comment.