Can someone walk me through getting a token or token wrapped in a cookie from an ESRI Portal and then where and how to pass it to the REST API to pull the geojson from a feature layer service?
Here is an example on how to create a token using Python:
import requests, json
# Disable warnings
requests.packages.urllib3.disable_warnings()
portal = 'portal.esri.com'
username = "jskinner@ESRI"
password = "**********"
tokenURL = 'https://{0}:7443/arcgis/sharing/rest/generateToken/'.format(portal)
params = {'f': 'pjson', 'username': username, 'password': password, 'client': 'requestip'}
r = requests.post(tokenURL, data = params, verify=False)
response = json.loads(r.content)
token = response['token']
print(token)
Jake already gave a good snippet to generate a token from python.
For the next step you need, to send a request to rest-endpoint to retrieve the GeoJSON from a feature layer, this could be done via a query operation with f and token parameters,e.g:
https://machine.domain.com/webadaptor/rest/services/USAStatesRiversCapitals/FeatureServer/2/query?where=1=1&f=geojson&token=tokenstring
so making an HTTP request to above URL with whatever programing language you're using.