File: associate

package info (click to toggle)
python3-openid 3.0.2%2Bgit20140828-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,672 kB
  • ctags: 2,679
  • sloc: python: 17,137; xml: 234; sh: 15; makefile: 4
file content (47 lines) | stat: -rwxr-xr-x 1,405 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python
"""Make an OpenID Assocition request against an endpoint
and print the results."""

import sys

from openid.store.memstore import MemoryStore
from openid.consumer import consumer
from openid.consumer.discover import OpenIDServiceEndpoint

from datetime import datetime

def verboseAssociation(assoc):
    """A more verbose representation of an Association.
    """
    d = assoc.__dict__
    issued_date = datetime.fromtimestamp(assoc.issued)
    d['issued_iso'] = issued_date.isoformat()
    fmt = """  Type: %(assoc_type)s
  Handle: %(handle)s
  Issued: %(issued)s [%(issued_iso)s]
  Lifetime: %(lifetime)s
  Secret: %(secret)r
"""
    return fmt % d

def main():
    if not sys.argv[1:]:
        print "Usage: %s ENDPOINT_URL..." % (sys.argv[0],)
    for endpoint_url in sys.argv[1:]:
        print "Associating with", endpoint_url

        # This makes it clear why j3h made AssociationManager when we
        # did the ruby port.  We can't invoke requestAssociation
        # without these other trappings.
        store = MemoryStore()
        endpoint = OpenIDServiceEndpoint()
        endpoint.server_url = endpoint_url
        c = consumer.GenericConsumer(store)
        auth_req = c.begin(endpoint)
        if auth_req.assoc:
            print verboseAssociation(auth_req.assoc)
        else:
            print "  ...no association."

if __name__ == '__main__':
    main()