Authentication¶
restgdf supports secured ArcGIS services in two common ways:
Pass an existing ArcGIS token in the request
datapayload.Wrap an
aiohttp.ClientSessioninArcGISTokenSessionso tokens are requested and refreshed automatically.
Direct token usage¶
If you already have a valid token, pass it directly when you create the layer:
import asyncio
from aiohttp import ClientSession
from restgdf import FeatureLayer
async def main():
async with ClientSession() as session:
layer = await FeatureLayer.from_url(
"https://example.com/arcgis/rest/services/Secured/FeatureServer/0",
session=session,
token="my-token",
)
return await layer.getgdf()
secured_gdf = asyncio.run(main())
You can also pass the same value via data={"token": "my-token"} if you prefer to keep all ArcGIS query params together.
Automatic token management¶
Use ArcGISTokenSession when you want the session to mint and refresh ArcGIS Online tokens for you:
import asyncio
from aiohttp import ClientSession
from restgdf import AGOLUserPass, ArcGISTokenSession, FeatureLayer
async def main():
async with ClientSession() as base_session:
token_session = ArcGISTokenSession(
session=base_session,
credentials=AGOLUserPass(
username="my-username",
password="my-password",
),
)
layer = await FeatureLayer.from_url(
"https://example.com/arcgis/rest/services/Secured/FeatureServer/0",
session=token_session,
)
return await layer.getgdf()
secured_gdf = asyncio.run(main())
Notes¶
ArcGISTokenSessiondelegates network I/O to the wrappedaiohttp.ClientSession.If you provide
credentials, the token is refreshed when it is missing or near expiry.Existing request kwargs and
datapayloads still work; the token session only augments them with auth data.