summaryrefslogtreecommitdiff
path: root/sleekxmpp/thirdparty/suelta/mechanisms/google_token.py
diff options
context:
space:
mode:
authorLance Stout <lancestout@gmail.com>2012-01-23 23:58:40 -0800
committerLance Stout <lancestout@gmail.com>2012-01-23 23:58:40 -0800
commit13158e3cdfc846d03e5698a9e507b7b5c426bfd6 (patch)
treed1e3199b1ec3b372f143621ad1cd4c00c4436310 /sleekxmpp/thirdparty/suelta/mechanisms/google_token.py
parentf06589c9132be151813e375b849c71be541f9439 (diff)
downloadslixmpp-13158e3cdfc846d03e5698a9e507b7b5c426bfd6.tar.gz
slixmpp-13158e3cdfc846d03e5698a9e507b7b5c426bfd6.tar.bz2
slixmpp-13158e3cdfc846d03e5698a9e507b7b5c426bfd6.tar.xz
slixmpp-13158e3cdfc846d03e5698a9e507b7b5c426bfd6.zip
Revert the X-GOOGLE-TOKEN mech to not perform HTTP requests.
Added new example for how to retrieve a Google token, following the best case, non-browser, workflow. Other thirdparty auth mechs (Facebook, MSN) follow a similar pattern of using an access token.
Diffstat (limited to 'sleekxmpp/thirdparty/suelta/mechanisms/google_token.py')
-rw-r--r--sleekxmpp/thirdparty/suelta/mechanisms/google_token.py58
1 files changed, 1 insertions, 57 deletions
diff --git a/sleekxmpp/thirdparty/suelta/mechanisms/google_token.py b/sleekxmpp/thirdparty/suelta/mechanisms/google_token.py
index 19d1b5a3..e641bb91 100644
--- a/sleekxmpp/thirdparty/suelta/mechanisms/google_token.py
+++ b/sleekxmpp/thirdparty/suelta/mechanisms/google_token.py
@@ -1,72 +1,16 @@
-import sys
-import logging
-try:
- from httplib import HTTPSConnection
- from urllib import urlencode
-except ImportError:
- from urllib.parse import urlencode
- from http.client import HTTPSConnection
-
from sleekxmpp.thirdparty.suelta.util import bytes
from sleekxmpp.thirdparty.suelta.sasl import Mechanism, register_mechanism
from sleekxmpp.thirdparty.suelta.exceptions import SASLError, SASLCancelled
-log = logging.getLogger(__name__)
-
class X_GOOGLE_TOKEN(Mechanism):
def __init__(self, sasl, name):
super(X_GOOGLE_TOKEN, self).__init__(sasl, name)
- self.check_values(['email', 'password', 'access_token'])
+ self.check_values(['email', 'access_token'])
def process(self, challenge=None):
- if not self.values.get('access_token', False):
- log.debug("SASL: Requesting auth token from Google")
- try:
- conn = HTTPSConnection('www.google.com')
- except:
- raise SASLError(self.sasl, 'Could not connect to Google')
- params = urlencode({
- 'accountType': 'GOOGLE',
- 'service': 'mail',
- 'Email': self.values['email'],
- 'Passwd': self.values['password']
- })
- headers = {
- 'Content-Type': 'application/x-www-form-urlencoded'
- }
- try:
- conn.request('POST', '/accounts/ClientLogin', params, headers)
- resp = conn.getresponse().read()
- data = {}
- for line in resp.split():
- k, v = line.split(b'=', 1)
- data[k] = v
- except Exception as e:
- raise e
- #raise SASLError(self.sasl, 'Could not retrieve login data')
-
- if b'SID' not in data:
- raise SASLError(self.sasl, 'Required data not found')
-
- params = urlencode({
- 'SID': data[b'SID'],
- 'LSID': data[b'LSID'],
- 'service': 'mail'
- })
- try:
- conn.request('POST', '/accounts/IssueAuthToken', params, headers)
- resp = conn.getresponse()
- data = resp.read().split()
- except:
- raise SASLError(self.sasl, 'Could not retrieve auth data')
- if not data:
- raise SASLError(self.sasl, 'Could not retrieve token')
-
- self.values['access_token'] = data[0]
-
email = bytes(self.values['email'])
token = bytes(self.values['access_token'])
return b'\x00' + email + b'\x00' + token