Пример #1
0
	def test_associate(self):
		registry = TestRegistry(test_handle)
		result = protocol.associate(registry, {})
		
		expecting = 'assoc_handle:72LSndh2ZN9VKt08GRPA6NaAEp0tTG2Puxq5vGnrqVk'
		expecting += 'F2iRPl001s1DXL9t+y6Gik8QswcPEZ6rlZymoHFHkpw==\n'
		expecting += 'assoc_type:HMAC-SHA1\nexpires_in:86400\n'
		expecting += 'mac_key:y/NsSugej//MGmCmUyauWLSlZKM=\n'
		
		self.failUnlessEqual(result, expecting)
Пример #2
0
	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)