コード例 #1
0
ファイル: resource.py プロジェクト: iffy/txOpenID
	def renderHTTP(self, ctx):
		"""
		OpenID provider flow begins here.
		
		@see: L{nevow.inevow.IResource}
		"""
		request = inevow.IRequest(ctx)
		requestData = protocol.OpenIDRequest(request)
		
		yield self.authenticate(ctx)
		
		output = False
		try:
			mode = requestData.get('openid.mode')
			registry = self.portal.realm.registry
			if(mode == 'associate'):
				output = protocol.associate(registry, requestData)
			elif(mode == 'checkid_immediate'):
				output = yield protocol.checkid_immediate(registry, requestData, self.user)
			elif(mode == 'checkid_setup'):
				output = yield protocol.checkid_setup(registry, requestData, self.user)
			elif(mode == 'check_authentication'):
				output = protocol.check_authentication(registry, requestData)
			else:
				output = util.handleError(requestData, "invalid mode '%s' specified" % requestData.get('openid.mode'))
		except:
			reason = failure.Failure()
			log.err(reason)
			
			# This should really never happen, since the protocol code itself
			# should attempt to give more informative messages when reasonable
			output = util.handleError(requestData, "A server error occurred: %s" % reason.getErrorMessage())
		
		if(isinstance(output, url.URL)):
			log.msg('REDIRECT: %r' % output)
			request.redirect(output)
			returnValue('')
		else:
			if(output is False):
				returnValue(super(ProviderPage, self).renderHTTP(ctx))
			log.msg('OUTPUT: %r' % output)
			returnValue(output)
コード例 #2
0
ファイル: test_protocol.py プロジェクト: iffy/txOpenID
	def _test_checkid_setup(self, setup_url, user):
		registry = TestRegistry(test_handle)
		result = yield protocol.checkid_setup(registry, TestRequest({
			'openid.mode'			: 'checkid_setup',
			'openid.identity'		: 'http://www.example.com/test',
			'openid.assoc_handle'	: test_handle,
			'openid.return_to'		: 'http://www.example.com/return',
			'openid.trust_root'		: 'http://www.example.com/trust',
		}), user=user)
		
		expecting_dict = {
			'openid.mode'			: 'checkid_setup',
			'openid.identity'		: 'http://www.example.com/test',
			'openid.assoc_handle'	: test_handle,
			'openid.return_to'		: 'http://www.example.com/return',
			'openid.trust_root'		: 'http://www.example.com/trust',
		}
		
		expecting = util.appendQuery(setup_url, expecting_dict)
		
		self.failUnless(isinstance(result, url.URL))
		self.failUnlessEqual(str(result), expecting)
コード例 #3
0
ファイル: test_protocol.py プロジェクト: iffy/txOpenID
	def test_checkid_setup_passes(self):
		registry = TestRegistry(test_handle)
		result = yield protocol.checkid_setup(registry, TestRequest({
			'openid.mode'			: 'checkid_setup',
			'openid.identity'		: 'http://www.example.com/test',
			'openid.assoc_handle'	: test_handle,
			'openid.return_to'		: 'http://www.example.com/return',
			'openid.trust_root'		: 'http://www.example.com/trust',
		}), user=TestUser())
		
		expecting_dict = {
			'openid.mode'			: 'id_res',
			'openid.identity'		: 'http://www.example.com/test',
			'openid.assoc_handle'	: test_handle,
			'openid.return_to'		: 'http://www.example.com/return',
			'openid.sig'			: 'HDvMdCLdF2UNw02pRurQWowEK84=',
			'openid.signed'			: 'identity,mode,return_to',
		}
		
		expecting = 'http://www.example.com/return?%s' % urllib.urlencode(expecting_dict)
		
		self.failUnless(isinstance(result, url.URL))
		self.failUnlessEqual(str(result), expecting)