Skip to content

Commit b666238

Browse files
Kevin Turnerlillialexis
Kevin Turner
authored andcommitted
contrib/associate: new script to make an association request
and print the results.
1 parent e86e87a commit b666238

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

contrib/associate

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env python
2+
"""Make an OpenID Assocition request against an endpoint
3+
and print the results."""
4+
5+
import sys
6+
7+
from openid.store.memstore import MemoryStore
8+
from openid.consumer import consumer
9+
from openid.consumer.discover import OpenIDServiceEndpoint
10+
11+
from datetime import datetime
12+
13+
def verboseAssociation(assoc):
14+
"""A more verbose representation of an Association.
15+
"""
16+
d = assoc.__dict__
17+
issued_date = datetime.fromtimestamp(assoc.issued)
18+
d['issued_iso'] = issued_date.isoformat()
19+
fmt = """ Type: %(assoc_type)s
20+
Handle: %(handle)s
21+
Issued: %(issued)s [%(issued_iso)s]
22+
Lifetime: %(lifetime)s
23+
Secret: %(secret)r
24+
"""
25+
return fmt % d
26+
27+
def main():
28+
if not sys.argv[1:]:
29+
print "Usage: %s ENDPOINT_URL..." % (sys.argv[0],)
30+
for endpoint_url in sys.argv[1:]:
31+
print "Associating with", endpoint_url
32+
33+
# This makes it clear why j3h made AssociationManager when we
34+
# did the ruby port. We can't invoke requestAssociation
35+
# without these other trappings.
36+
store = MemoryStore()
37+
endpoint = OpenIDServiceEndpoint()
38+
endpoint.server_url = endpoint_url
39+
c = consumer.GenericConsumer(store)
40+
auth_req = c.begin(endpoint)
41+
if auth_req.assoc:
42+
print verboseAssociation(auth_req.assoc)
43+
else:
44+
print " ...no association."
45+
46+
if __name__ == '__main__':
47+
main()

0 commit comments

Comments
 (0)