def key_jar_from_config(config: dict) -> KeyJar: """Get key jar from dict by issuer""" kj = KeyJar() logger = logging.getLogger(__name__).getChild("key_jar_from_config") for (issuer, v) in config.items(): if "jwks_url" in v: url = v.get("jwks_url") logger.info("Reading keys for issuer %s from %s", issuer, url) kj.add_url(issuer, url) elif "jwks_path" in v: filename = v.get("jwks_path") logger.info("Reading keys for issuer %s from %s", issuer, filename) kj.import_jwks_from_file(filename, issuer) else: logger.warning("No keys defined for issuer %s", issuer) return kj
def key_setup(): # Copy dynamically created files to there places in the base_data information tree. key_jar = KeyJar() key_jar.import_jwks_from_file(os.path.join(dir_path, "flask_op/static/fed_keys.json"), "") _jwks = key_jar.export_jwks_as_json(issuer="") with open('base_data/umu.se/https%3A%2F%2F127.0.0.1%3A5000/jwks.json', "w") as fp: fp.write(_jwks) for _key_file, _port in [(os.path.join(dir_path, "flask_rp/static/fed_keys.json"), 4000), (os.path.join(dir_path, "flask_rp/static/fed_keys_auto.json"), 4001)]: if os.path.isfile(_key_file): key_jar = KeyJar() key_jar.import_jwks_from_file(_key_file, "") _jwks = key_jar.export_jwks_as_json(issuer="") _file = 'base_data/lu.se/https%3A%2F%2F127.0.0.1%3A{}/jwks.json'.format(_port) with open(_file, "w") as fp: fp.write(_jwks)
# Initialize the oidc_provider after views to be able to set correct urls app.signing_service = init_sign_service(app) return app if __name__ == "__main__": domain = '127.0.0.1' op_port = 5000 rp_spec = [("../flask_rp/static/fed_keys.json", 4000), ("../flask_rp/static/fed_keys_auto.json", 4001)] # Copy dynamically created files to there places in the base_data information tree. key_jar = KeyJar() key_jar.import_jwks_from_file("../flask_op/static/fed_keys.json", "") _jwks = key_jar.export_jwks_as_json(issuer_id="") with open( 'base_data/umu.se/https%3A%2F%2F{}%3A{}/jwks.json'.format( domain, op_port), "w") as fp: fp.write(_jwks) for _key_file, _port in rp_spec: if os.path.isfile(_key_file): key_jar = KeyJar() key_jar.import_jwks_from_file(_key_file, "") _jwks = key_jar.export_jwks_as_json(issuer_id="") _file = 'base_data/lu.se/https%3A%2F%2F{}%3A{}%2Flocal/jwks.json'.format( domain, _port) with open(_file, "w") as fp: fp.write(_jwks)