Beispiel #1
0
def authorize(app_id, app_secret):
	url = 'https://www.facebook.com/dialog/oauth'
	params = {'client_id' : app_id,
			'response_type' : 'code',
			'state' : state,
			'redirect_uri' : 'http://localhost:8000/'}
	if scope:
		params['scope'] = scope
	url = url + '?' + urllib.urlencode(params)

	print 'Need authorize, Start Server, Please wait ...'
	httpd = BaseHTTPServer.HTTPServer(('', 8000), RequestHandler)

	webbrowser.open(url)
	httpd.handle_request()
	httpd.server_close()

	if not code:
		raise Exception('Code is None')
	url = 'https://graph.facebook.com/oauth/access_token'
	params = {'client_id' : app_id,
			'client_secret' : app_secret,
			'redirect_uri' : 'http://localhost:8000/',
			'code' : code}
	url = url + '?' + urllib.urlencode(params)
	response = urllib2.urlopen(url)
	result = util.urldecode(response.read().strip())
	long_term_access_token = result['access_token']
	return long_term_access_token
Beispiel #2
0
def authorize(client_id, client_secret):
	url = 'https://github.com/login/oauth/authorize'
	params = {'client_id' : client_id,
			'state' : state}
	if scope:
		params['scope'] = scope
	url = url + '?' + urllib.urlencode(params)

	print 'Need authorize, Start Server, Please wait ...'
	httpd = BaseHTTPServer.HTTPServer(('', 8000), RequestHandler)

	webbrowser.open(url)
	httpd.handle_request()
	httpd.server_close()

	if not code:
		raise Exception('Code is None')
	url = 'https://github.com/login/oauth/access_token'
	params = {'client_id' : client_id,
			'client_secret' : client_secret,
			'code' : code}
	url = url + '?' + urllib.urlencode(params)
	response = urllib2.urlopen(url)
	result = util.urldecode(response.read().strip())
	access_token = result['access_token']
	return access_token
Beispiel #3
0
 def title_str(self, obj):
     canon = obj.as_link().canonical_outputs()
     tags = ''.join(
         format_html('<span>{}</span>', tag.strip())
         for tag in obj.tags.split(',')) if obj.tags else ''
     return format_html(
         '<a href="/{}">'
         '<img src="/{}/{}" class="favicon" onerror="this.remove()">'
         '</a>'
         '<a href="/{}/{}">'
         '<b class="status-{}">{}</b>'
         '</a>', obj.archive_path, obj.archive_path, canon['favicon_path'],
         obj.archive_path, canon['wget_path'] or '',
         'fetched' if obj.latest_title or obj.title else 'pending',
         urldecode(htmldecode(obj.latest_title or obj.title or ''))[:128]
         or 'Pending...') + mark_safe(f'<span class="tags">{tags}</span>')
Beispiel #4
0
 def title_str(self, obj):
     canon = obj.as_link().canonical_outputs()
     tags = ''.join(
         format_html(
             '<a href="/admin/core/snapshot/?tags__id__exact={}"><span class="tag">{}</span></a> ',
             tag.id, tag) for tag in obj.tags.all() if str(tag).strip())
     return format_html(
         '<a href="/{}">'
         '<img src="/{}/{}" class="favicon" onerror="this.remove()">'
         '</a>'
         '<a href="/{}/index.html">'
         '<b class="status-{}">{}</b>'
         '</a>', obj.archive_path, obj.archive_path, canon['favicon_path'],
         obj.archive_path,
         'fetched' if obj.latest_title or obj.title else 'pending',
         urldecode(htmldecode(obj.latest_title or obj.title or ''))[:128]
         or 'Pending...') + mark_safe(f' <span class="tags">{tags}</span>')
Beispiel #5
0
	def do_GET(self):
		try:
			self.send_response(200)
			self.send_header('Content-Type', 'text/plain')
			self.end_headers()
			s = urlparse(self.path).query
			result = util.urldecode(s)
			global code
			if result['state'] == state:
				code = result['code']
				self.wfile.write('Hello world')
			else:
				print self.path
				self.wfile.write(self.path)
		except (KeyboardInterrupt, SystemExit):
			raise
		except:
			self.send_response(500)
			self.send_header('Content-type', 'text/html')
			self.end_headers()
			self.wfile.write(cgitb.html(sys.exc_info(), context=10))
Beispiel #6
0
	def do_GET(self):
		try:
			host = self.headers.get('Host')
			url = 'http://' + host + self.path
			s = urlparse(self.path).query
			result = util.urldecode(s)
			for key in result:
				value = result[key]
				result[key] = value.decode('utf-8')

			info = openid_consumer.complete(result, url)

			display_identifier = info.getDisplayIdentifier()

			# Copy from https://github.com/openid/python-openid/blob/master/examples/consumer.py
			if info.status == consumer.FAILURE and display_identifier:
				# In the case of failure, if info is non-None, it is the
				# URL that we were verifying. We include it in the error
				# message to help the user figure out what happened.
				fmt = "Verification of %s failed: %s"
				message = fmt % (display_identifier, info.message)
			elif info.status == consumer.SUCCESS:
				# This is a successful verification attempt. If this
				# was a real application, we would do our login,
				# comment posting, etc. here.
				fmt = "You have successfully verified %s as your identity."
				message = fmt % (display_identifier,)
				if info.endpoint.canonicalID:
					# You should authorize i-name users by their canonicalID,
					# rather than their more human-friendly identifiers.  That
					# way their account with you is not compromised if their
					# i-name registration expires and is bought by someone else.
					message += ("  This is an i-name, and its persistent ID is %s"
								% (info.endpoint.canonicalID,))
			elif info.status == consumer.CANCEL:
				# cancelled
				message = 'Verification cancelled'
			elif info.status == consumer.SETUP_NEEDED:
				if info.setup_url:
					message = 'Setup needed : %s' % (info.setup_url,)
				else:
					# This means auth didn't succeed, but you're welcome to try
					# non-immediate mode.
					message = 'Setup needed'
			else:
				# Either we don't understand the code or there is no
				# openid_url included with the error. Give a generic
				# failure message. The library should supply debug
				# information in a log.
				message = 'Verification failed.'

			print
			print
			print message
			email_value_key = ('http://openid.net/srv/ax/1.0', 'value.email')
			firstname_value_key = ('http://openid.net/srv/ax/1.0', 'value.firstname')
			lastname_value_key = ('http://openid.net/srv/ax/1.0', 'value.lastname')
			country_value_key = ('http://openid.net/srv/ax/1.0', 'value.country')
			language_value_key = ('http://openid.net/srv/ax/1.0', 'value.language')
			if info.status == consumer.SUCCESS:
				if email_value_key in info.message.args:
					email = info.message.args[email_value_key]
					print 'Your Email is : %s' % email
				if firstname_value_key in info.message.args:
					firstname = info.message.args[firstname_value_key]
					print 'Your Firstname is : %s' % firstname
				if lastname_value_key in info.message.args:
					lastname = info.message.args[lastname_value_key]
					print 'Your Lastname is : %s' % lastname
				if country_value_key in info.message.args:
					country = info.message.args[country_value_key]
					print 'Your Country is : %s' % country
				if language_value_key in info.message.args:
					language = info.message.args[language_value_key]
					print 'Your Language is : %s' % language
			print
			print

			self.send_response(200)
			self.send_header('Content-Type', 'application/json')
			self.end_headers()
			self.wfile.write(json.dumps(result, indent=4))
		except (KeyboardInterrupt, SystemExit):
			raise
		except:
			self.send_response(500)
			self.send_header('Content-type', 'text/html')
			self.end_headers()
			self.wfile.write(cgitb.html(sys.exc_info(), context=10))
Beispiel #7
0
def _parse_response(response):
	body = response.read().strip()
	return util.urldecode(body)
Beispiel #8
0
    def do_GET(self):
        try:
            host = self.headers.get('Host')
            url = 'http://' + host + self.path
            s = urlparse(self.path).query
            result = util.urldecode(s)
            for key in result:
                value = result[key]
                result[key] = value.decode('utf-8')

            info = openid_consumer.complete(result, url)

            display_identifier = info.getDisplayIdentifier()

            # Copy from https://github.com/openid/python-openid/blob/master/examples/consumer.py
            if info.status == consumer.FAILURE and display_identifier:
                # In the case of failure, if info is non-None, it is the
                # URL that we were verifying. We include it in the error
                # message to help the user figure out what happened.
                fmt = "Verification of %s failed: %s"
                message = fmt % (display_identifier, info.message)
            elif info.status == consumer.SUCCESS:
                # This is a successful verification attempt. If this
                # was a real application, we would do our login,
                # comment posting, etc. here.
                fmt = "You have successfully verified %s as your identity."
                message = fmt % (display_identifier, )
                if info.endpoint.canonicalID:
                    # You should authorize i-name users by their canonicalID,
                    # rather than their more human-friendly identifiers.  That
                    # way their account with you is not compromised if their
                    # i-name registration expires and is bought by someone else.
                    message += (
                        "  This is an i-name, and its persistent ID is %s" %
                        (info.endpoint.canonicalID, ))
            elif info.status == consumer.CANCEL:
                # cancelled
                message = 'Verification cancelled'
            elif info.status == consumer.SETUP_NEEDED:
                if info.setup_url:
                    message = 'Setup needed : %s' % (info.setup_url, )
                else:
                    # This means auth didn't succeed, but you're welcome to try
                    # non-immediate mode.
                    message = 'Setup needed'
            else:
                # Either we don't understand the code or there is no
                # openid_url included with the error. Give a generic
                # failure message. The library should supply debug
                # information in a log.
                message = 'Verification failed.'

            print
            print
            print message
            email_value_key = ('http://openid.net/srv/ax/1.0', 'value.email')
            firstname_value_key = ('http://openid.net/srv/ax/1.0',
                                   'value.firstname')
            lastname_value_key = ('http://openid.net/srv/ax/1.0',
                                  'value.lastname')
            country_value_key = ('http://openid.net/srv/ax/1.0',
                                 'value.country')
            language_value_key = ('http://openid.net/srv/ax/1.0',
                                  'value.language')
            if info.status == consumer.SUCCESS:
                if email_value_key in info.message.args:
                    email = info.message.args[email_value_key]
                    print 'Your Email is : %s' % email
                if firstname_value_key in info.message.args:
                    firstname = info.message.args[firstname_value_key]
                    print 'Your Firstname is : %s' % firstname
                if lastname_value_key in info.message.args:
                    lastname = info.message.args[lastname_value_key]
                    print 'Your Lastname is : %s' % lastname
                if country_value_key in info.message.args:
                    country = info.message.args[country_value_key]
                    print 'Your Country is : %s' % country
                if language_value_key in info.message.args:
                    language = info.message.args[language_value_key]
                    print 'Your Language is : %s' % language
            print
            print

            self.send_response(200)
            self.send_header('Content-Type', 'application/json')
            self.end_headers()
            self.wfile.write(json.dumps(result, indent=4))
        except (KeyboardInterrupt, SystemExit):
            raise
        except:
            self.send_response(500)
            self.send_header('Content-type', 'text/html')
            self.end_headers()
            self.wfile.write(cgitb.html(sys.exc_info(), context=10))
Beispiel #9
0
def _parse_response(response):
    body = response.read().strip()
    return util.urldecode(body)