Skip to content

Commit bde6e09

Browse files
committed
allow KGClient to use device flow
1 parent 9e3aeb4 commit bde6e09

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fairgraph/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ class KGClient(object):
8787
and "core.kg.ebrains.eu" to work with the production KG.
8888
client_id (str, optional): For use together with client_secret in place of the token if you have a service account.
8989
client_secret (str, optional): The client secret to use for authentication. Required if client_id is provided.
90+
allow_interactive (bool, default True): if true, allow authentication via web browser
9091
9192
Raises:
9293
ImportError: If the kg_core package is not installed.
@@ -99,6 +100,7 @@ def __init__(
99100
host: str = "core.kg-ppd.ebrains.eu",
100101
client_id: Optional[str] = None,
101102
client_secret: Optional[str] = None,
103+
allow_interactive = True
102104
):
103105
if not have_kg_core:
104106
raise ImportError(
@@ -114,7 +116,14 @@ def __init__(
114116
try:
115117
self._kg_client_builder = kg(host).with_token(os.environ["KG_AUTH_TOKEN"])
116118
except KeyError:
117-
raise AuthenticationError("Need to provide either token or client id/secret.")
119+
if allow_interactive:
120+
iam_config_url = "https://iam.ebrains.eu/auth/realms/hbp/.well-known/openid-configuration"
121+
self._kg_client_builder = kg(host).with_device_flow(
122+
client_id="kg-core-python",
123+
open_id_configuration_url=iam_config_url
124+
)
125+
else:
126+
raise AuthenticationError("Need to provide either token or client id/secret.")
118127
self._kg_client = self._kg_client_builder.build()
119128
self.__kg_admin_client = None
120129
self.host = host

0 commit comments

Comments
 (0)