Twitter連携によってDMが読まれる不安を抱えている皆様へ

  • ウェブサービスTwitter との連携について、定期的に話題にのぼるこの問題
    • Twitter の OAuth には、認可の種類が "Read & Write" か "Read-only" しかないため、サードパーティとタイムラインを連携させたいだけなどのケースでも、ダイレクトメッセージに対する読み込み権限を与えてしまう
<?php

$username = $_GET['username'];
$password = $_GET['password'];

if ($password) {
    $home_timeline = file_get_contents("https://$username:$password@twitter-basicauth.appspot.com/1/statuses/home_timeline.xml");
    $direct_messages = file_get_contents("https://$username:$password@twitter-basicauth.appspot.com/1/direct_messages.xml");
    $verify_credentials = file_get_contents("https://$username:$password@twitter-basicauth.appspot.com/1/account/verify_credentials.xml");
}

?>
<html>
    <head>
        <title>TOBASIC! sample</title>
    </head>
    <body>
        <a href="https://twitter-basicauth.appspot.com/oauth/authorize?consumer_key=SDCNLkvhJ0UZEAAUDK5zeg">authorize</a><br />
        <a href="https://twitter-basicauth.appspot.com/oauth/authorize?consumer_key=SDCNLkvhJ0UZEAAUDK5zeg&scope=without_direct_messages">authorize(without_direct_messages)</a><br />
        <a href="https://twitter-basicauth.appspot.com/oauth/authorize?consumer_key=SDCNLkvhJ0UZEAAUDK5zeg&scope=account">authorize(account)</a><br />
        <? if ($home_timeline) { ?>
            <br />
            home_timeline:<br />
            <textarea cols="80" rows="40"><?= $home_timeline ?></textarea><br />
        <? } ?>
        <? if ($direct_messages) { ?>
            <br />
            direct_messages:<br />
            <textarea cols="80" rows="40"><?= $direct_messages ?></textarea><br />
        <? } ?>
        <? if ($verify_credentials) { ?>
            <br />
            verify_credentials:<br />
            <textarea cols="80" rows="40"><?= $verify_credentials ?></textarea><br />
        <? } ?>
    </body>
</html>
  • 利用手順
    • ユーザに認可させるための URL をブラウザで開く

https://twitter-basicauth.appspot.com/oauth/authorize?consumer_key=&scope=&state=

      • consumer key の登録と設定については後述
      • scope は without_direct_messages(ダイレクトメッセージ以外)または account(アカウント情報のみ)
      • state は callback にそのまま渡される任意の文字列
    • 認可後、設定された callback URI にリダイレクトされるので username と password を受け取る

?username=&password=&state=

      • callback の登録と設定については後述
      • username と password は Basic 認証で使用する
  • デメリット
    • id:asannou にダイレクトメッセージを読まれる不安が残る