Resumen
Allows you to sign in to a portal.
Debate
To share content or run Ready To Use Tools, you must be signed in to a portal. The portal can be either an ArcGIS Enterprise portal or an ArcGIS Online portal.
To add a portal connection, click the Project tab on the ribbon and click the Portals page. For more information, see Manage portal connections from ArcGIS Pro.
SignInToPortal will add the portal URL to your portal connections (if necessary), sign in, and set the portal to active. If it's run in the Python window, the portal will be set as the active portal (if different) and added to the portal connections for future ArcGIS Pro or stand-alone Python sessions. However, if it's run in a stand-alone Python session, the portal information will be used only for the duration of the active Python session. If the portal is active and you're signed in to it, you don't need to run the SignInToPortal function. Running a script inside or outside of ArcGIS Pro automatically uses the current active portal.
When signing in as a portal user or in to accounts based on the following supported portal authentication configurations, different parameters may be required:
- If the portal uses built-in security, provide a username and password.
- If the portal uses public key infrastructure (PKI) authentication, provide a PKCS12 formatted certificate file (.pfx or .p12) and certificate password.
You can also provide a PEM formatted certificate and key file. Both the certificate and the key have the .pem file extension.
- If the portal uses Integrated Windows Authentication (IWA), leave the username and password parameters empty. Providing a Windows username and password is not supported.
Signing in to a portal that uses IWA or PKI is not supported on a Linux machine.
Sintaxis
SignInToPortal (portal_url, {username}, {password}, {cert_file}, {key_file}, {token}, {token_referer}, {token_expiry})
Parámetro | Explicación | Tipo de datos |
portal_url | The URL of the portal to sign in to. | String |
username | The username of the user signing in to the portal. If the portal uses IWA, leave this parameter empty. You can only sign in as the current Windows user. | String |
password | The password of the user signing in to the portal. If the portal uses PKI authentication, use the password to the PKCS12 certificate file. If the portal uses IWA, leave this parameter empty. | String |
cert_file | The path to the certificate file. If the portal uses PKI authentication, use the path to the PKCS12 formatted certificate file (.pfx or .p12) or the PEM formatted certificate file (.pem). | String |
key_file | The path to the key file. If the portal uses PKI authentication, use the path to the PEM formatted key file (.pem). | String |
token | The token that will be used to authenticate with the portal. An ArcGIS portal token can be created using any of the following:
When using a token to authenticate, the token, token_referer, and token_expiry values must be specified. | String |
token_referer | The referer that will be used to generate the token (if applicable). | String |
token_expiry | The expiration time stamp for the token. This is a value measured in the number of seconds since epoch. Nota:The API that produces the token may return the expiry value in seconds or milliseconds. | Integer |
Tipo de datos | Explicación |
Dictionary | A dictionary of key value pairs for expires, referer, and token values. |
Muestra de código
Sign in to a portal that uses built-in security.
import arcpy
arcpy.SignInToPortal("https://webadaptorhost.domain.com/webadaptorname",
'username', 'password')
Sign in to a portal that uses public key infrastructure (PKI authentication) using a PKCS12 formatted certificate file (.pfx or .p12) and password.
import arcpy
arcpy.SignInToPortal("https://webadaptorhost.domain.com/webadaptorname",
cert_file="C:\\path\\to\\mycert.pfx",
password="cert.password")
Sign in to a portal that uses public key infrastructure (PKI authentication) using a PEM formatted certificate file (.pem) and key file (.pem).
import arcpy
arcpy.SignInToPortal("https://webadaptorhost.domain.com/webadaptorname",
cert_file="C:\\path\\to\\mycert.pem",
key_file="C:\\path\\to\\mykey.pem")
Sign in to a portal that uses Integrated Windows Authentication (IWA) by omitting the username and password.
import arcpy
arcpy.SignInToPortal("https://webadaptorhost.domain.com/webadaptorname")
Sign in to a portal using a token retrieved from an ArcGIS portal's generateToken REST endpoint.
import arcpy
import requests
# assemble arguments into a dictionary
# for additional help on the generateToken REST service, see your portal documentation
portal_url = "https://example.com/portal/"
gen_token_url = f"{portal_url}sharing/rest/generateToken"
params = {"f": "json", # Response format
"username": "username", # Your ArcGIS Portal username
"password": "password", # Your ArcGIS Portal password
"referer": gen_token_url, # URL of the referring application (usually your portal)
"expiration": 60 # Token expiration time in minutes (default: 60)
}
# get a token using python's requests module
resp = requests.post(gen_token_url, data=params)
# check response. If failed, show response.text
assert resp.status_code == 200, resp.text
# now use token with SignInToPortal
token = resp.json()['token']
token_expiry = int(resp.json()['expires']/1000) # convert to seconds since generateToken returns milliseconds
resp = arcpy.SignInToPortal(portal_url, token=token, token_referer=portal_url, token_expiry=token_expiry)
Sign in to a portal using a password saved in Windows Credential Manager.
import arcpy
import keyring
portal = "https://example.com/portal/"
username = "user"
password = keyring.get_password(portal, username)
arcpy.SignInToPortal(portal, username, password)