まぁshtterを適当に改変しただけなんですけど
実行すると色々と生成して実行すべきコマンドと引数が表示されます
curl~と実行すればOK
いつもながらLinux & Bashで動作確認
#!/bin/bash
CKEY=""
CSECRET=""
TMPDIR="/tmp"
GenerateNonce()
{
dd if=/dev/urandom bs=1024 count=1 2>/dev/null | md5sum | cut -c1-32
}
GetTimeStamp()
{
date +%s
}
Encode()
{
echo "$@" | sed 's/./\0\n/g' | grep '[^-._~0-9a-zA-Z]' | sort | uniq | while read l
do
if [ "$l" == "" ]; then l=" "; fi
HEX="`echo -n \"$l\" | hexdump -e '16/1 "%02X" "\n"'`"
if [ "$l" == "/" ]; then l="\/"; fi
echo "s/$l/$HEX"
done | sed 's/ *$//; s/\([0-9A-Z]\{2\}\)/%\1/g; s/$/\/g/' >"$TMPDIR/rep.sed"
echo "$@" | sed -f "$TMPDIR/rep.sed"
rm "$TMPDIR/rep.sed"
}
GenerateHash()
{
EURL="`Encode $2`"
EPARAM="`Encode $3`"
QUERY="$1&$EURL&$EPARAM"
HASH="`echo -n \"$QUERY\" | openssl sha1 -hmac \"$CSECRET&$ASECRET\" -binary | openssl base64`"
Encode "$HASH"
}
GetRequestToken()
{
URL="http://gdd-2010-quiz-japan.appspot.com/oauth/XXXXXXXXXXXXXXXXXXXXXXXX"
NONCE="`GenerateNonce`"
TIMESTAMP="`GetTimeStamp`"
PARAM="hello=world&oauth_consumer_key=$CKEY&oauth_nonce=$NONCE&oauth_signature_method=HMAC-SHA1&oauth_timestamp=$TIMESTAMP&oauth_token=&oauth_version=1.0"
HASH="`GenerateHash \"POST\" \"$URL\" \"$PARAM\"`"
HEADER="Authorization: OAuth realm=\"devquiz\", oauth_consumer_key=\"$CKEY\", oauth_nonce=\"$NONCE\", oauth_signature=\"$HASH\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"$TIMESTAMP\", oauth_token=\"\", oauth_version=\"1.0\""
echo "curl --data 'hello=world' --header '$HEADER' $URL"
}
GetRequestToken
0 件のコメント:
コメントを投稿