Esempio n. 1
0
    def give_access(self, form):
        parser = FormParser()
        parser.feed(form)
        parser.close()

        access = self.opener.open(parser.url, urllib.urlencode(parser.params))
        return access.geturl()
Esempio n. 2
0
    def auth_url(self):
        url = 'https://oauth.vk.com/authorize?'

        for param in self.data:
            url += '%s=%s&' % (param, self.data[param])

        auth_object = self.opener.open(url)
        form = auth_object.read()

        parser = FormParser()
        parser.feed(form)
        parser.close()
        parser.params['email'] = self.login
        parser.params['pass'] = self.password

        auth_object = self.opener.open(parser.url,
                                       urllib.urlencode(parser.params))
        return auth_object.read()
Esempio n. 3
0
	def __init__(self, login, password):
		scope=["photos"]
		opener = urllib2.build_opener( \
			urllib2.HTTPCookieProcessor(cookielib.CookieJar()), \
			urllib2.HTTPRedirectHandler())
		response = opener.open(\
			"http://oauth.vk.com/oauth/authorize?" + \
			"redirect_uri=http://oauth.vk.com/blank.html&response_type=token&" + \
			"client_id=%s&scope=%s&display=wap" % (self.client_id, ",".join(scope)))
		doc = response.read()
		parser = FormParser()
		parser.feed(doc)
		parser.close()
		if not parser.form_parsed or parser.url is None or "pass" not in parser.params or \
		"email" not in parser.params:
			self.err_code=1;
			self.err_text="unknown error"
		else:	
			parser.params["email"] = login
			parser.params["pass"] = password
			if parser.method == "POST" or parser.method == "post":
				response = opener.open(parser.url, urllib.urlencode(parser.params))
			else:
				self.err_code=2
				self.err_text="Method '%s'" % parser.method
		if not self.err_code:	
			if urlparse(response.geturl()).path != "/blank.html":
				# Need to give access to requested scope
				parser.ClearParser()
				parser.feed(response.read())
				parser.close()
				if not parser.form_parsed or parser.url is None:
					self.err_code=3;
					self.err_text="unknown error"
				if parser.method == "POST" or parser.method == "post":
					response = opener.open(parser.url, urllib.urlencode(parser.params))
				else:
					self.err_code=4
					self.err_text="Method '%s'" % parser.method
		if not self.err_code:
			if urlparse(response.geturl()).path != "/blank.html":
				self.err_code=5
				self.err_text="failure"
			else:
				answer = dict(self.split_key_value(kv_pair) for kv_pair in urlparse(response.geturl()).fragment.split("&"))
				if "access_token" not in answer or "user_id" not in answer:
					self.err_code=6
					self.err_text="wrong parameters"
				self.token = answer["access_token"]
				self.user_id = answer["user_id"]