Skip to content

Commit 68760c9

Browse files
authored
Update OIDC config to match dotnet utils (#73)
* Allow multiple scopes * Configurable authority
1 parent d915ee6 commit 68760c9

5 files changed

Lines changed: 14 additions & 9 deletions

File tree

cognite/extractorutils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
Cognite extractor utils is a Python package that simplifies the development of new extractors.
1717
"""
1818

19-
__version__ = "1.2.0"
19+
__version__ = "1.2.1"

cognite/extractorutils/authentication.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class from ``cognite.extractorutils.configtools`` your extractor will be configu
2222
import logging
2323
import time
2424
from dataclasses import dataclass
25-
from typing import Any, Dict
25+
from typing import Any, Dict, List
26+
from urllib.parse import urljoin
2627

2728
import requests
2829

@@ -32,13 +33,14 @@ class from ``cognite.extractorutils.configtools`` your extractor will be configu
3233
@dataclass
3334
class AuthenticatorConfig:
3435
"""
35-
Configuration parameters for Azure AD
36+
Configuration parameters for an OIDC flow
3637
"""
3738

3839
tenant: str
3940
client_id: str
40-
scope: str
41+
scopes: List[str]
4142
secret: str
43+
authority: str = "https://login.microsoftonline.com/"
4244
min_ttl: float = 30 # minimum time to live: refresh token ahead of expiration
4345

4446

@@ -67,9 +69,11 @@ def _request(self) -> Dict[str, Any]:
6769
"tenant": self._config.tenant,
6870
"client_secret": self._config.secret,
6971
"grant_type": "client_credentials",
70-
"scope": self._config.scope,
72+
"scope": " ".join(self._config.scopes),
7173
}
72-
url = f"https://login.microsoftonline.com/{self._config.tenant}/oauth2/v2.0/token"
74+
base_url = urljoin(self._config.authority, self._config.tenant)
75+
76+
url = f"{base_url}/oauth2/v2.0/token"
7377
r = requests.post(url, data=body)
7478
_logger.debug("Request AAD token: %d %s", r.status_code, r.reason)
7579
return r.json()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cognite-extractor-utils"
3-
version = "1.2.0"
3+
version = "1.2.1"
44
description = "Utilities for easier development of extractors for CDF"
55
authors = ["Mathias Lohne <mathias.lohne@cognite.com>"]
66
license = "Apache-2.0"

tests/tests_unit/test_authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
from cognite.extractorutils.authentication import Authenticator, AuthenticatorConfig
2020

21-
config = AuthenticatorConfig(tenant="tid", client_id="cid", scope="scp", secret="scrt",)
21+
config = AuthenticatorConfig(tenant="tid", client_id="cid", scopes=["scp"], secret="scrt",)
2222

2323

2424
def token(expires_in: int, t: str):

tests/tests_unit/test_configtools.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ def test_get_cognite_client_from_aad(self):
175175
tenant: foo
176176
client_id: cid
177177
secret: scrt
178-
scope: scp
178+
scopes:
179+
- scp
179180
min_ttl: 40
180181
project: tenant-name
181182
external-id-prefix: "test_"

0 commit comments

Comments
 (0)