Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.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
使用bash、curl命令行向cas进行身份验证_Bash_Authentication_Curl_Command Line_Cas - Fatal编程技术网

使用bash、curl命令行向cas进行身份验证

使用bash、curl命令行向cas进行身份验证,bash,authentication,curl,command-line,cas,Bash,Authentication,Curl,Command Line,Cas,我找到了这个脚本,用于使用curl和bash通过cas进行身份验证,从命令行获取受保护的URL(请参见下面的代码)。然而,我无法让脚本工作。我已经验证了我能够提取LoginTicket、JSESSION并提供了正确的用户名和密码。然而,即使我已经验证我提供了所有正确的信息,cas服务器似乎也没有对此做出反应。它只是一次又一次地返回登录页面,没有任何错误消息 这个脚本仍然是一种可行的方法吗?或者我需要使用cas REST-API吗?如果我想使用命令行获得有效的cas票证,现在是adays # Ta

我找到了这个脚本,用于使用curl和bash通过cas进行身份验证,从命令行获取受保护的URL(请参见下面的代码)。然而,我无法让脚本工作。我已经验证了我能够提取LoginTicket、JSESSION并提供了正确的用户名和密码。然而,即使我已经验证我提供了所有正确的信息,cas服务器似乎也没有对此做出反应。它只是一次又一次地返回登录页面,没有任何错误消息

这个脚本仍然是一种可行的方法吗?或者我需要使用cas REST-API吗?如果我想使用命令行获得有效的cas票证,现在是adays

# Taken from https://gist.github.com/dodok1/4134605
# Usage: cas-get.sh {url} {username} {password} # If you have any errors try removing the redirects to get more information
# The service to be called, and a url-encoded version (the url encoding isn't perfect, if you're encoding complex stuff you may wish to replace with a different method)
DEST="$1"
ENCODED_DEST=`echo "$DEST" | perl -p -e 's/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg' | sed 's/%2E/./g' | sed 's/%0A//g'`

#IP Addresses or hostnames are fine here
CAS_HOSTNAME=team.eea.sk

#Authentication details. This script only supports username/password login, but curl can handle certificate login if required
USERNAME=$2
PASSWORD=$3

#Temporary files used by curl to store cookies and http headers
COOKIE_JAR=.cookieJar
HEADER_DUMP_DEST=.headers
rm $COOKIE_JAR
rm $HEADER_DUMP_DEST

#The script itself is below

#Visit CAS and get a login form. This includes a unique ID for the form, which we will store in CAS_ID and attach to our form submission. jsessionid cookie will be set here
CAS_ID=`curl -s -k -c $COOKIE_JAR https://$CAS_HOSTNAME/cas/login?service=$ENCODED_DEST | grep name=.lt | sed 's/.*value..//' | sed 's/\".*//'`

#Submit the login form, using the cookies saved in the cookie jar and the form submission ID just extracted. We keep the headers from this request as the return value should be a 302 including a "ticket" param which we'll need in the next request
curl -s -k --data "username=$USERNAME&password=$PASSWORD&lt=$CAS_ID&_eventId=submit" -i -b $COOKIE_JAR -c $COOKIE_JAR https://$CAS_HOSTNAME/cas/login?service=$ENCODED_DEST -D $HEADER_DUMP_DEST -o /dev/null

#Linux may not need this line but my response from the previous call has retrieving windows-style linebreaks in OSX
#dos2unix $HEADER_DUMP_DEST > /dev/null

#Visit the URL with the ticket param to finally set the casprivacy and, more importantly, MOD_AUTH_CAS cookie. Now we've got a MOD_AUTH_CAS cookie, anything we do in this session will pass straight through CAS
CURL_DEST=`grep Location $HEADER_DUMP_DEST | sed 's/Location: //'`
curl -s -k -b $COOKIE_JAR -c $COOKIE_JAR $CURL_DEST

#If our destination is not a GET we'll need to do a GET to, say, the user dashboard here

#Visit the place we actually wanted to go to
curl -s -k -b $COOKIE_JAR "$DEST"

您可以像提取“lt”值一样提取“execution”值,并将其包含在第二个curl调用中