Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/74.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在应用程序中使用LDAP进行身份验证_Python_R_Shiny_Ldap - Fatal编程技术网

Python 如何在应用程序中使用LDAP进行身份验证

Python 如何在应用程序中使用LDAP进行身份验证,python,r,shiny,ldap,Python,R,Shiny,Ldap,我的公司使用LDAP服务器对Active Directory进行身份验证。我需要使用此验证远程托管的Shiny应用程序的用户。我设法用Python进行了身份验证,但需要将其移植到R: import ldap from getpass import getpass username = "user_name" password = getpass(prompt='Password: ', stream=None) ldap_server = "ldap://company-ldap-server:

我的公司使用LDAP服务器对Active Directory进行身份验证。我需要使用此验证远程托管的Shiny应用程序的用户。我设法用Python进行了身份验证,但需要将其移植到R:

import ldap
from getpass import getpass
username = "user_name"
password = getpass(prompt='Password: ', stream=None)
ldap_server = "ldap://company-ldap-server:636"

try:
    # Create connection with LDAP server and set options
    conn = ldap.initialize(ldap_server)
    conn.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
    conn.set_option(ldap.OPT_X_TLS_NEWCTX, 0)

    # Authenticate by trying to connect
    conn.simple_bind_s(username, password)

    # Retrieve this user's name and email (for authorization)
    info = conn.search_s("DC=ad,DC=company,DC=com", ldap.SCOPE_SUBTREE, f"cn={username}*")
    conn.unbind_s()

except Exception:
    print("ERROR: Could not connect")
以下是我在R中尝试过的:

library(RCurl)

ldap_server <- "ldap://company-ldap-server:636"
user <- "user_name"
RCurl::getURL(ldap_server, .opts=list(userpwd = paste0(user, "@ad.company.com:", 
                                                       .rs.askForPassword("Password: "))
                                      )
)

不确定如何部署应用程序,仅供参考:Shiny Server的商业版本支持LDAP身份验证,请参阅。此外,开源解决方案还提供LDAP支持。Shiny Server的付费版本并不理想,尽管如果没有其他选择,我可能会去那里。Shinyproxy需要docker,这以前是一个巨大的痛苦。也许是时候再试试了。shinyproxy提供了一些容器示例。用这种方式部署/配置我的第一个应用程序(也使用LDAP)只花了我几个小时。尽管shinyproxy很有趣,但我已经确认docker也不是一个选项。不。我只是通过调用Python脚本来处理它,该脚本通过系统调用来执行LDAP身份验证。可能是一个稍微优雅的方法使用网状。但在我看来,这一切都很尴尬。
# Python
conn = ldap.initialize(ldap_server)
conn.simple_bind_s(username, password)

# R
getURL(ldap_server, .opts=list(userpwd = "...."))