Select to view content in your preferred language

Check if the user logged in to ArcGIS Online or Portal

790
1
04-30-2020 02:38 PM
AhmadSALEH1
Occasional Contributor III

Hi all,

Is there a way to check if the user logged in to ArcGIS Online or Portal in Python API

I have a script that publishes zipped shp files to my portal, but before publishing, I would like to check if I am logged in and authenticated to publish

for now, I am using gis.users.me  which returns None if am not logged in, but looking for something different than this

from arcgis.gis import GIS
gis = GIS()
print(gis.users.me)‍‍‍

Thank you,

Ahmad

1 Reply
Ofir_Mazor
New Contributor II

There is still no straigth forward approch for this but I think I found a work around by getting the current user role in the portal information. 
If the user is not signed-in the value in the role key will be empty string (''). Once the user is signed-in, it's role will be set in the portal info dictionary.

from arcpy import GetPortalInfo, GetActivePortalURL

def portal_sign_in_check() -> None:
    portal_info: dict = GetPortalInfo(portal_URL = GetActivePortalURL())
    if portal_info['role'] == '':
        print('User is not signed-in to portal')
    else:
        print('User is signed-in to portal')

 
Example of the portal info dictionary when the user is not signed-in:

{'SSL_enabled': False, 'portal_version': 9.2, 'role': '', 'organization': 'My Organization', 'organization_type': ''}

 

Example of the portal info dictionary when the user is signed-in:

 

{'SSL_enabled': True, 'portal_version': 9.2, 'role': 'org_admin', 'organization': 'My Oraganization', 'organization_type': ''}

 

 

Tags (1)