SignInToPortal

摘要

允许您登录门户。

说明

必须登录门户才可以共享内容或运行即用型工具。 门户可以是 ArcGIS Enterprise 门户或 ArcGIS Online 门户。

要添加门户连接,请单击功能区中的工程选项卡,然后单击门户页面。 有关详细信息,请参阅通过 ArcGIS Pro 管理门户连接

SignInToPortal 会将门户 URL 添加到门户连接(如有必要),请登录并将门户设置为活动状态。 如果在 Python 窗口中运行该操作,则门户会被设置为活动门户(如果两者不是同一门户)并添加到门户连接以用于未来的 ArcGIS Pro 或独立 Python 会话。 但是,如果在独立 Python 会话中运行该操作,则系统将只能在 Python 会话活动期间使用门户信息。 如果门户处于活动状态并且您已登录,则无需运行 SignInToPortal 函数。 在 ArcGIS Pro 内部或外部运行脚本时会自动使用当前活动门户。

当以门户用户身份登录时或当根据以下受支持的门户身份验证配置登录帐户时,可能需要不同的参数:

  • 如果门户使用内置安全性,提供用户名和密码。
  • 如果门户使用公钥基础设施 (PKI) 身份验证,则提供 PKCS12 格式的证书文件(.pfx.p12)和证书密码。

    还可以提供 PEM 格式的证书和密钥文件。 证书和密钥的文件扩展名均为 .pem

  • 如果门户使用集成的 Windows 身份验证 (IWA),保持用户名和密码参数为空。 不支持提供 Windows 用户名和密码。

不支持在 Linux 计算机上登录使用 IWA 或 PKI 的门户。

语法

SignInToPortal (portal_url, {username}, {password}, {cert_file}, {key_file}, {token}, {token_referer}, {token_expiry})
参数说明数据类型
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:

  • The GetSigninToken function within an authenticated session
  • The generateToken REST service on Portal for ArcGIS.
  • The SignInToPortal function

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 timestamp for the token. This is a value measured in the number of seconds since epoch.

注:

The API that produces the token may return the expiry value in seconds or milliseconds.

Integer
返回值
数据类型说明
Dictionary

expiresreferertoken 值的键值对字典。

代码示例

SignInToPortal 示例 1

登录使用内置安全性的门户。

import arcpy

arcpy.SignInToPortal("https://webadaptorhost.domain.com/webadaptorname", 
                     'username', 'password')
SignInToPortal 示例 2

使用 PKCS12 格式的证书文件(.pfx.p12)和密码登录使用公钥基础设施(PKI 身份验证)的门户。

import arcpy

arcpy.SignInToPortal("https://webadaptorhost.domain.com/webadaptorname", 
                     cert_file="C:\\path\\to\\mycert.pfx", 
                     password="cert.password")
SignInToPortal 示例 3

使用 PEM 格式的证书文件 (.pem) 和密钥文件 (.pem) 登录使用公钥基础设施(PKI 身份验证)的门户。

import arcpy

arcpy.SignInToPortal("https://webadaptorhost.domain.com/webadaptorname", 
                     cert_file="C:\\path\\to\\mycert.pem", 
                     key_file="C:\\path\\to\\mykey.pem")
SignInToPortal 示例 4

不输入用户名和密码来登录使用集成的 Windows 身份验证 (IWA) 的门户。

import arcpy

arcpy.SignInToPortal("https://webadaptorhost.domain.com/webadaptorname")
SignInToPortal 示例 5

使用从 ArcGIS 门户的 generateToken REST 端点检索的令牌登录门户。


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)

相关主题