diff options
author | Kevin Turner <http://keturn.net/> | 2010-03-31 11:02:23 +0800 |
---|---|---|
committer | lillialexis <lillialexis@gmail.com> | 2010-06-19 01:08:20 +0800 |
commit | b666238f61574d12f922c40bf7917ec916df7125 (patch) | |
tree | e0bf7f4bf42321f17ce4a3b9b62eb374b5616b3d | |
parent | e86e87a60360c06f18536c0e6ab9939b8399026e (diff) | |
download | openid-b666238f61574d12f922c40bf7917ec916df7125.tar.gz |
contrib/associate: new script to make an association request2.2.5
and print the results.
-rwxr-xr-x | contrib/associate | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/contrib/associate b/contrib/associate new file mode 100755 index 0000000..4cb05c3 --- /dev/null +++ b/contrib/associate @@ -0,0 +1,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() |