1

我正在编写一个简单的 python 脚本,它将使用OSCAR 协议与 AIM 服务器交互。它包括一个有点复杂的握手协议。您基本上必须向特定 URL 发送 GET 请求,接收 XML 或 JSON 编码回复,提取特殊会话令牌和密钥,然后使用令牌和密钥生成响应。

我尝试按照这些步骤进行操作,但最后一个过程失败了。这是我的代码:

class simpleOSCAR:
  def __init__(self, username, password):
    self.username = username
    self.password = password

    self.open_aim_key = 'whatever'
    self.client_name = 'blah blah blah'
    self.client_version = 'yadda yadda yadda'


  def authenticate(self):

    # STEP 1
    url = 'https://api.screenname.aol.com/auth/clientLogin?f=json'
        data = urllib.urlencode( [
                 ('k', self.open_aim_key), 
                 ('s', self.username),
                 ('pwd', self.password), 
                 ('clientVersion', self.client_version),
                 ('clientName', self.client_name)]
                )

    response = urllib2.urlopen(url, data)
    json_response = simplejson.loads(urllib.unquote(response.read()))

    session_secret = json_response['response']['data']['sessionSecret']
    host_time = json_response['response']['data']['hostTime']
    self.token = json_response['response']['data']['token']['a']

    # STEP 2
    self.session_key = base64.b64encode(hmac.new(self.password, session_secret, sha256).digest())

    #STEP 3
    uri = "http://api.oscar.aol.com/aim/startOSCARSession?"

    data = urllib.urlencode([   
                    ('a', self.token),  
                    ('clientName', self.client_name),
                    ('clientVersion', self.client_version),
                    ('f', 'json'),
                    ('k', self.open_aim_key), 
                    ('ts', host_time), 
                                    ]
                )
    urldata = uri+data
    hashdata = "GET&" + urllib.quote("http://api.oscar.aol.com/aim/startOSCARSession?") + data

    digest = base64.b64encode(hmac.new(self.session_key, hashdata, sha256).digest())

    urldata =  urldata + "&sig_sha256=" + digest

    print urldata + "\n"

    response = urllib2.urlopen(urldata)
    json_response = urllib.unquote(response.read())

    print json_response

if __name__ == '__main__':
so = simpleOSCAR("aimscreenname", "somepassword")
so.authenticate()

我从服务器收到以下响应:

{ "response" : {
                 "statusCode":401, 
                 "statusText":"Authentication Required. statusDetailCode 1014",
                 "statusDetailCode":1014, 
                 "data":{
                           "ts":1235878395
                         }
               }
}

我尝试以各种方式对其进行故障排除,但我生成的 URL 看起来与登录流示例中显示的 URL 相同。然而,它失败了。

知道我在这里做错了什么吗?我是否对值进行了错误的散列?我是否对某些内容进行了不正确的编码?我的会话超时了吗?

4

2 回答 2

1

尝试使用Twisted 的 OSCAR 支持而不是自己编写?它没有看到很多维护,但我相信它有效。

于 2009-06-17T04:03:55.803 回答
0

URI 编码您的摘要?

-莫克斯福德

于 2009-03-13T23:00:37.383 回答