def test_query_rel(self): wf = WebFinger() query = wf.query("acct:[email protected]", ["http://webfinger.net/rel/profile-page", "vcard"]) assert query == "https://example.com/.well-known/webfinger?resource" \ "=acct%3Abob%40example.com&rel=http%3A%2F%2Fwebfinger" \ ".net%2Frel%2Fprofile-page&rel=vcard"
def test_query_acct(self): wf = WebFinger(OIC_ISSUER) query = wf.query("acct:[email protected]") assert query == "https://example.com/.well-known/webfinger?resource" \ "=acct%3Acarol%40example.com&rel=http%3A%2F%2Fopenid" \ ".net%2Fspecs%2Fconnect%2F1.0%2Fissuer"
def discover(self, *arg, **kwargs): wf = WebFinger(OIC_ISSUER) wf.httpd = PBase() _url = wf.query(kwargs["principal"]) self.trace.request("URL: %s" % _url) url = wf.discovery_query(kwargs["principal"]) return url
def test_query_acct_host_forced(self): wf = WebFinger(OIC_ISSUER) query = wf.query("http://example.com/carol", host='forced.co') assert query == "https://forced.co/.well-known/webfinger?resource" \ "=http%3A%2F%2Fexample.com%2Fcarol&rel=http%3A%2F%2Fopenid" \ ".net%2Fspecs%2Fconnect%2F1.0%2Fissuer"
def test_query_rel_host_forced(self): wf = WebFinger() query = wf.query( "acct:[email protected]", ["http://webfinger.net/rel/profile-page", "vcard"], host="forced.com:3000", ) assert ( query == "https://forced.com:3000/.well-known/webfinger?resource" "=acct%3Abob%40example.com&rel=http%3A%2F%2Fwebfinger" ".net%2Frel%2Fprofile-page&rel=vcard")
def test_query_acct(self): wf = WebFinger(OIC_ISSUER) query = wf.query("acct:[email protected]") assert query == "https://example.com/.well-known/webfinger?resource=acct%3Acarol%40example.com&rel=http%3A%2F%2Fopenid.net%2Fspecs%2Fconnect%2F1.0%2Fissuer"
def test_query_rel(self): wf = WebFinger() query = wf.query("acct:[email protected]", ["http://webfinger.net/rel/profile-page", "vcard"]) assert query == "https://example.com/.well-known/webfinger?resource=acct%3Abob%40example.com&rel=http%3A%2F%2Fwebfinger.net%2Frel%2Fprofile-page&rel=vcard"
def test_query_device(self): wf = WebFinger() query = wf.query(resource="device:p1.example.com") assert query == 'https://p1.example.com/.well-known/webfinger?resource=device%3Ap1.example.com'
def test_query_device_host_forced(self): wf = WebFinger() query = wf.query(resource="device:p1.example.com", host='forced.com') assert query == 'https://forced.com/.well-known/webfinger' \ '?resource=device%3Ap1.example.com'
# # HTTP/1.1 200 OK # Access-Control-Allow-Origin * # Content-Type: application/jrd+json # # { # "subject" : "acct:[email protected]", # "links": # [{ # "rel": "http://openid.net/specs/connect/1.0/issuer", # "href": "https://openid.example.com" # }] # } userid = "*****@*****.**" wf = WebFinger() query = wf.query("acct:%s" % userid, rel=OIC_ISSUER) print query r = requests.request("GET", query, verify=False) jwt = json.loads(r.text) print json.dumps(jwt, sort_keys=True, indent=4, separators=(',', ': ')) print ######################################################### wf = WebFinger() wf.httpd = PBase(verify_ssl=False) url = wf.discovery_query("acct:%s" % userid) print "The user should be redirected here for login", url
""" import json from oic.oauth2 import PBase import requests from oic.utils.webfinger import WebFinger, OIC_ISSUER __author__ = 'roland' # ===================================================================== # Using only very basic functions and methods # Initiate the WebFinger class wf = WebFinger() # contruct the webfinger query URL query = wf.query("acct:[email protected]", rel=OIC_ISSUER) print(query) r = requests.request("GET", query, verify=False) # parse the JSON returned by the website and dump the content to # standard out jwt = json.loads(r.text) print(json.dumps(jwt, sort_keys=True, indent=4, separators=(',', ': '))) # ===================================================================== # A bit more high level wf = WebFinger()
Shows off how you can do OpenID Connect dynamic configuration discovery """ import json import requests from oic.oic import Client from oic.oic import OIDCONF_PATTERN from oic.utils.webfinger import WebFinger from oic.utils.webfinger import OIC_ISSUER __author__ = 'roland' # ============================================================================= wf = WebFinger() query = wf.query("acct:[email protected]:8060", rel=OIC_ISSUER) r = requests.request("GET", query, verify=False) jwt = json.loads(r.text) url = jwt["links"][0]["href"] print("Provider:", url) # Construct the URL used to get the provider configuration url = OIDCONF_PATTERN % url[:-1] print("Provider info url:", url) r = requests.request("GET", url, verify=False)