Created
January 28, 2010 08:44
-
-
Save keturn/288560 to your computer and use it in GitHub Desktop.
openid/contrib/associate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
"""Make an OpenID Assocition request against an endpoint | |
and print the results.""" | |
from datetime import datetime | |
import sys | |
from openid.store.memstore import MemoryStore | |
from openid.consumer import consumer | |
from openid.consumer.discover import OpenIDServiceEndpoint | |
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment