Skip to content

Commit e736fa3

Browse files
colin-geowebb-bentomkralidis
authored
Custom esri token service (geopython#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 <[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]>
1 parent d240a82 commit e736fa3

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

docs/source/data-publishing/ogcapi-features.rst

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,11 @@ To publish an ESRI `Feature Service`_ or `Map Service`_ specify the URL for the
145145

146146
* ``id_field`` will often be ``OBJECTID``, ``objectid``, or ``FID``.
147147
* If the map or feature service is not shared publicly, the ``username`` and ``password`` fields can be set in the
148-
configuration to authenticate into the service.
148+
configuration to authenticate to the service.
149+
* If the map or feature service is self-hosted and not shared publicly, the ``token_service`` and optional ``referer`` fields
150+
can be set in the configuration to authenticate to the service.
151+
152+
To publish from an ArcGIS online hosted service:
149153

150154
.. code-block:: yaml
151155
@@ -158,6 +162,24 @@ To publish an ESRI `Feature Service`_ or `Map Service`_ specify the URL for the
158162
crs: 4326 # Optional crs (default is EPSG:4326)
159163
username: username # Optional ArcGIS username
160164
password: password # Optional ArcGIS password
165+
token_service: https://your.server.com/arcgis/sharing/rest/generateToken # optional URL to your generateToken service
166+
referer: https://your.server.com # optional referer, defaults to https://www.arcgis.com if not set
167+
168+
To publish from a self-hosted service that is not publicly accessible, the ``token_service`` field is required:
169+
170+
.. code-block:: yaml
171+
172+
providers:
173+
- type: feature
174+
name: ESRI
175+
data: https://your.server.com/arcgis/rest/services/your-layer/MapServer/0
176+
id_field: objectid
177+
time_field: date_in_your_device_time_zone # Optional time field
178+
crs: 4326 # Optional crs (default is EPSG:4326)
179+
username: username # Optional ArcGIS username
180+
password: password # Optional ArcGIS password
181+
token_service: https://your.server.com/arcgis/sharing/rest/generateToken # Optional url to your generateToken service
182+
referer: https://your.server.com # Optional referer, defaults to https://www.arcgis.com if not set
161183
162184
GeoJSON
163185
^^^^^^^

pygeoapi/provider/esri.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,9 @@ def __init__(self, provider_def):
6262
self.crs = provider_def.get('crs', '4326')
6363
self.username = provider_def.get('username')
6464
self.password = provider_def.get('password')
65+
self.token_url = provider_def.get('token_service', ARCGIS_URL)
66+
self.token_referer = provider_def.get('referer', GENERATE_TOKEN_URL)
6567
self.token = None
66-
6768
self.session = Session()
6869

6970
self.login()
@@ -194,16 +195,15 @@ def login(self):
194195
msg = 'Missing ESRI login information, not setting token'
195196
LOGGER.debug(msg)
196197
return
197-
198198
params = {
199199
'f': 'pjson',
200200
'username': self.username,
201201
'password': self.password,
202-
'referer': ARCGIS_URL
202+
'referer': self.token_referer
203203
}
204204

205205
LOGGER.debug('Logging in')
206-
with self.session.post(GENERATE_TOKEN_URL, data=params) as r:
206+
with self.session.post(self.token_url, data=params) as r:
207207
self.token = r.json().get('token')
208208
# https://enterprise.arcgis.com/en/server/latest/administer/windows/about-arcgis-tokens.htm
209209
self.session.headers.update({

0 commit comments

Comments
 (0)