Get brief human-readable info about XRI OpenID with Python?

225 Views Asked by At

I'd like to be able to tell to the site visitor that comes with his/her OpenID: you are using your XYZ id for the first time on mysite - please create your sceen name, where XYZ is a nice token that makes sense. For example - XYZ could be the provider name.

I'd like to find a solution that works for OpenID as defined in the standard - i.e. work for XRI type of ID - extensible resource identifier.

urlparse (as suggested by RichieHindle) works for url-type openid, but does not work in general, e.g. for i-name IDs like "=somename". There are many other forms of valid OpenID string that don't even closely look like url.

Thanks.

1

There are 1 best solutions below

2
RichieHindle On

Since OpenIDs are URLs, this might be the cleanest way in the absence of built-in support in Janrain:

from urlparse import urlparse
openid_str = "http://myprovider/myname" # str(openid_obj)
parts = urlparse(openid_str)
provider_name = parts[1]
print (provider_name)  # Prints myprovider