dokuwiki OAuth tests and examples

These are example requests for the dokuwiki oauth plugin.

You can access the DokuWiki OAuth API by making requests to doku.php?do[oauth]=XXX or simply by making any request adding the oauth_signature request-parameter.

Get and install oauth-utils for the command-line tool (oauthsign) used in this example.

curl "\[oauth\]=addconsumer&consumer_key=key&consumer_secret=secret"
oauthsign -x "" key secret accesskey accesssecret

Here's a script that walks through the complete oAuth Core 1.0 protocol:

OAUTHSIGN=$(which oauthsign)


TOKENFILE=`mktemp /tmp/oauth.XXXXXXXXXX` || exit 1
function cleanup { rm $TOKENFILE; }
trap cleanup EXIT

echo " +++ add consumer."
curl "${DW}?do\[oauth\]=addconsumer&consumer_key=${CK}&consumer_secret=${CS}&callback_url=${CU}"

echo " +++ getting request token.."
$OAUTHSIGN -X -f $TOKENFILE -w -e "${DWOA}requesttoken" "$CK" "$CS" \
        || (echo " !!! no request token returned."; exit 1) || exit 1;

echo " +++ Authorization."
REQTOK=`cat $TOKENFILE | awk '/oauth_token_key=(.*)/{ print substr($1,17);}'`
echo "visit ${DWOA}authorize&oauth_token=${REQTOK}"
echo -n "to authorize this request token and press enter.."

echo " +++ exchanging request token for access token"
$OAUTHSIGN -X -f $TOKENFILE -w  "${DWOA}accesstoken" \
        || (echo " !!! token exchange failed"; exit 1) || exit 1;

echo " +++ making test request.."
$OAUTHSIGN -x -f $TOKENFILE "${DW}?do=admin" \
        | grep "Logged in as:"
     #  || echo " !!! test request failed"

echo " +++ performing XML-RPC.."
curl --data-ascii @- -H "Content-Type: text/xml" \
        `oauthsign -p -G -f $TOKENFILE ${DWRPC}` \
<< EOF
<?xml version="1.0" encoding="iso-8859-1"?>

Note: Apache rewrite-rules modify the base-string! The query-parameters and URL must not be modified before they are passed to the PHP script (Using DirectoryIndex doku.php works, redirecting from index.php does not!)

wiki/dokuoauth_examples.txt · Last modified: 09.03.2009 18:26 by rgareus