Esri / ArcREST

python package for REST API (AGS, AGOL, webmap JSON, etc..)
Apache License 2.0
192 stars 155 forks source link

referer for AGSTokenSecurityHandler #231

Closed adamkerz closed 8 years ago

adamkerz commented 8 years ago

I've forked ArcREST on the 20th April (db5f57304f5c20e9855c5f60e5eafe23e3476106) and am trying to use AGSTokenSecurityHandler with a referer based token and a GPTask. Unfortunately, although it retrieves a token correctly, it looks like it does not add the referer header to the submit job request.

I'm currently hacking it to get my POC working, but, firstly, wondering if I've missed something, as it looks like it's been implemented for the PortalTokenSecurityHandler, but AGSTokenSecurityHandler seems to be hard coded to requestip. Secondly, is this something that you could easily implement? I'm writing some pretty hacky code to get it working, probably partly because I'm struggling to understand the class hierarchy, and there appears to be urllib handlers and then ArcREST handlers, which I think are different things...

I'm happy to implement it if you can give me some guidance as to the best way, but my current code really isn't that great.

Cheers,

Adam

achapkowski commented 8 years ago

@adamkerz I'll take a look at it today.

achapkowski commented 8 years ago

Just committed a fix. Please pull the latest.

import arcrest
if __name__ == "__main__":
    username = "username"
    password = "password"
    referer = "mysite.someotherpart.com"
    org_url = "https://mysite.someotherpart.com/arcgis"
    url = "https://mysite.someotherpart.com/arcgis/rest/services/SampleWorldCities/MapServer"
    sh = arcrest.AGSTokenSecurityHandler(username, password, org_url=org_url)
    sh.referer_url = referer
    ms = arcrest.ags.MapService(url=url, securityHandler=sh, initialize=True)
    print ms.capabilities