@@ -87,6 +87,7 @@ class KGClient(object):
87
87
and "core.kg.ebrains.eu" to work with the production KG.
88
88
client_id (str, optional): For use together with client_secret in place of the token if you have a service account.
89
89
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
90
91
91
92
Raises:
92
93
ImportError: If the kg_core package is not installed.
@@ -99,6 +100,7 @@ def __init__(
99
100
host : str = "core.kg-ppd.ebrains.eu" ,
100
101
client_id : Optional [str ] = None ,
101
102
client_secret : Optional [str ] = None ,
103
+ allow_interactive = True
102
104
):
103
105
if not have_kg_core :
104
106
raise ImportError (
@@ -114,7 +116,14 @@ def __init__(
114
116
try :
115
117
self ._kg_client_builder = kg (host ).with_token (os .environ ["KG_AUTH_TOKEN" ])
116
118
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." )
118
127
self ._kg_client = self ._kg_client_builder .build ()
119
128
self .__kg_admin_client = None
120
129
self .host = host
0 commit comments