Esri / ArcREST

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

AGOLTokenSecurityHandler and/or ArcGIS Desktop login? #216

Closed simoxu001 closed 8 years ago

simoxu001 commented 8 years ago

I don't know if it's possible to access the credentials obtained by logging in AGOL in ArcCatalog/ArcMap in my own tool built upon ArcREST.

by doing this, I only need to login from ArcGIS Desktop once and then I will be able to run multiple tools without the need to create new AGOLTokenSecurityHandlers every time for each of them.

thanks

MikeMillerGIS commented 8 years ago

Use the https://github.com/Esri/ArcREST/blob/master/src/arcrest/security/security.py#L877

simoxu001 commented 8 years ago

Thanks @MikeMillerGIS , Could you give a little bit more details? or even better, a snippet of code if possible?

simoxu001 commented 8 years ago

Does that mean I can use ArcGISTokenSecurityHandler for the securityHandler in the following code?

fs = FeatureService(
    url=url,
    securityHandler=agsSH,
    proxy_port=proxy_port,
    proxy_url=proxy_url,
    initialize=True)
MikeMillerGIS commented 8 years ago

Yes, but the script must be run from within ArcMap or ArcCatalog. There are examples in the tools folder.

BrunoCaimar commented 8 years ago

Hello, I've just used it.

I created a method to return a securityHandler using ArcMap connection. I hope it helps.

from arcresthelper import featureservicetools

def get_security_handler_using_arcmap_connection():
    """
    Returns a valid securityhandler object using the current ArcGIS Online connection

    ** Only works inside ArcMAP / ArcCatalog - Versions > 10.2 **

    Returns: securityhandler or a Exception if connection is not valid
    """
    security_info = {'security_type': 'ArcGIS',
                     'proxy_url': None,
                     'proxy_port': None}

    fs_tools = featureservicetools.featureservicetools(security_info)

    if not fs_tools.valid:
        raise Exception(fs_tools.message)

    return fs_tools.securityhandler
simoxu001 commented 8 years ago

Thanks @MikeMillerGIS @BrunoCaimar ArcGISTokenSecurityHandler works