~ubuntuone-pqm-team/canonical-identity-provider/trunk

« back to all changes in this revision

Viewing changes to doctests/stories/openid/per-version/referer-cookie.txt

  • Committer: Danny Tamez
  • Date: 2010-04-21 15:29:24 UTC
  • Revision ID: danny.tamez@canonical.com-20100421152924-lq1m92tstk2iz75a
Canonical SSO Provider (Open Source) - Initial Commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Copyright 2010 Canonical Ltd.  This software is licensed under the
 
2
GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 
 
4
= Recording the Referer in a Cookie =
 
5
 
 
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.
 
9
 
 
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
 
13
the OpenID provider).
 
14
 
 
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.
 
18
 
 
19
First we'll set up our OpenID consumer:
 
20
 
 
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())
 
27
 
 
28
    >>> openid_store = MemoryStore()
 
29
    >>> consumer = Consumer(session={}, store=openid_store)
 
30
 
 
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.
 
34
 
 
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"
 
42
 
 
43
 
 
44
== Cleanup ==
 
45
 
 
46
    >>> setDefaultFetcher(None)