1
Copyright 2010 Canonical Ltd. This software is licensed under the
2
GNU Affero General Public License version 3 (see the file LICENSE).
4
= Recording the Referer in a Cookie =
6
In order to maintain reasonable quality of service for important RPs,
7
we need some way that the load balancer can categorise connections by
8
the RP they originate from.
10
The first request in the OpenID authentication process can easily be
11
categorised by looking at the "Referer" request header, but that can't
12
be done for subsequent requests (whose "Referer" header will point at
15
To solve this problem, we set a cookie at the beginning of the
16
authentication request containing the referer value. The load
17
balancer can then use this to classify the subsequent requests.
19
First we'll set up our OpenID consumer:
21
>>> from openid.consumer.consumer import Consumer
22
>>> from openid.fetchers import setDefaultFetcher
23
>>> from openid.store.memstore import MemoryStore
24
>>> from canonical.signon.testing.openidhelpers import (
25
... make_identifier_select_endpoint, PublisherFetcher)
26
>>> setDefaultFetcher(PublisherFetcher())
28
>>> openid_store = MemoryStore()
29
>>> consumer = Consumer(session={}, store=openid_store)
31
Now when we start the OpenID authentication request, the "Referer"
32
header gets saved into a cookie. The cookie has no expiry date set,
33
so will not last beyond the current web browser session.
35
>>> request = consumer.beginWithoutDiscovery(
36
... make_identifier_select_endpoint(PROTOCOL_URI))
37
>>> browser.addHeader('Referer', 'http://example.com/referer')
38
>>> browser.open(request.redirectURL(
39
... 'http://launchpad.dev/', 'http://launchpad.dev/+openid-consumer'))
40
>>> print browser.cookies['openid_referer']
41
"http://example.com/referer"
46
>>> setDefaultFetcher(None)