Skip to content

Commit 7cefe90

Browse files
lackasCFenner
andauthored
Expose oauth constants (#725)
* Unify SCOPE and OAuth constants in abstract base Move AUTHORIZE_URL, TOKEN_URL, and SCOPE to PyViCareAbstractOAuthManager as the single source of truth. Both PyViCareOAuthManager and PyViCareBrowserOAuthManager now import from there. * Define individual scope constants per CFenner review Replace VIESSMANN_SCOPE list with individual constants: SCOPE_IOT, SCOPE_USER, SCOPE_OFFLINE_ACCESS, SCOPE_INTERNAL. Each manager builds its own scope list from these constants, making it explicit which scopes each flow requests. * Apply suggestions from code review Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com> * Update PyViCareOAuthManager.py --------- Co-authored-by: Christopher Fenner <9592452+CFenner@users.noreply.github.com>
1 parent 8cd3bb7 commit 7cefe90

File tree

3 files changed

+24
-10
lines changed

3 files changed

+24
-10
lines changed

PyViCare/PyViCareAbstractOAuthManager.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@
1515
logger.addHandler(logging.NullHandler())
1616

1717
API_BASE_URL = 'https://api.viessmann-climatesolutions.com/iot/v2'
18+
AUTHORIZE_URL = 'https://iam.viessmann-climatesolutions.com/idp/v3/authorize'
19+
TOKEN_URL = 'https://iam.viessmann-climatesolutions.com/idp/v3/token'
20+
21+
SCOPE_IOT = "IoT"
22+
SCOPE_USER = "User"
23+
SCOPE_OFFLINE_ACCESS = "offline_access"
24+
SCOPE_INTERNAL = "internal"
1825

1926

2027
class AbstractViCareOAuthManager:

PyViCare/PyViCareBrowserOAuthManager.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,21 @@
77
from authlib.common.security import generate_token
88
from authlib.integrations.requests_client import OAuth2Session
99

10-
from PyViCare.PyViCareAbstractOAuthManager import AbstractViCareOAuthManager
10+
from PyViCare.PyViCareAbstractOAuthManager import (
11+
AUTHORIZE_URL,
12+
SCOPE_IOT,
13+
SCOPE_OFFLINE_ACCESS,
14+
SCOPE_USER,
15+
TOKEN_URL,
16+
AbstractViCareOAuthManager,
17+
)
1118
from PyViCare.PyViCareUtils import (PyViCareBrowserOAuthTimeoutReachedError,
1219
PyViCareInvalidCredentialsError)
1320

1421
logger = logging.getLogger('ViCare')
1522
logger.addHandler(logging.NullHandler())
1623

17-
AUTHORIZE_URL = 'https://iam.viessmann-climatesolutions.com/idp/v3/authorize'
18-
TOKEN_URL = 'https://iam.viessmann-climatesolutions.com/idp/v3/token'
1924
REDIRECT_PORT = 51125
20-
VIESSMANN_SCOPE = ["IoT User", "offline_access"]
2125
AUTH_TIMEOUT = 60 * 3
2226

2327

@@ -50,7 +54,7 @@ def __load_or_create_new_session(self):
5054
def __execute_browser_authentication(self):
5155
redirect_uri = f"http://localhost:{REDIRECT_PORT}"
5256
oauth_session = OAuth2Session(
53-
self.client_id, redirect_uri=redirect_uri, scope=VIESSMANN_SCOPE, code_challenge_method='S256')
57+
self.client_id, redirect_uri=redirect_uri, scope=[SCOPE_IOT, SCOPE_USER, SCOPE_OFFLINE_ACCESS], code_challenge_method='S256')
5458
code_verifier = generate_token(48)
5559
authorization_url, _ = oauth_session.create_authorization_url(AUTHORIZE_URL, code_verifier=code_verifier)
5660

PyViCare/PyViCareOAuthManager.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@
88
from authlib.common.security import generate_token
99
from authlib.integrations.requests_client import OAuth2Session
1010

11-
from PyViCare.PyViCareAbstractOAuthManager import AbstractViCareOAuthManager
11+
from PyViCare.PyViCareAbstractOAuthManager import (
12+
AUTHORIZE_URL,
13+
SCOPE_IOT,
14+
SCOPE_USER,
15+
TOKEN_URL,
16+
AbstractViCareOAuthManager,
17+
)
1218
from PyViCare.PyViCareUtils import (PyViCareInvalidConfigurationError,
1319
PyViCareInvalidCredentialsError)
1420

1521
logger = logging.getLogger('ViCare')
1622
logger.addHandler(logging.NullHandler())
1723

18-
AUTHORIZE_URL = 'https://iam.viessmann-climatesolutions.com/idp/v3/authorize'
19-
TOKEN_URL = 'https://iam.viessmann-climatesolutions.com/idp/v3/token'
2024
REDIRECT_URI = "vicare://oauth-callback/everest"
21-
VIESSMANN_SCOPE = ["IoT User"]
2225

2326

2427
class ViCareOAuthManager(AbstractViCareOAuthManager):
@@ -55,7 +58,7 @@ def __create_new_session(self, username, password, token_file=None):
5558
oauth sessions object
5659
"""
5760
oauth_session = OAuth2Session(
58-
self.client_id, redirect_uri=REDIRECT_URI, scope=VIESSMANN_SCOPE, code_challenge_method='S256')
61+
self.client_id, redirect_uri=REDIRECT_URI, scope=[SCOPE_IOT, SCOPE_USER], code_challenge_method='S256')
5962
code_verifier = generate_token(48)
6063
authorization_url, _ = oauth_session.create_authorization_url(AUTHORIZE_URL, code_verifier=code_verifier)
6164
logger.debug("Auth URL is: %s", authorization_url)

0 commit comments

Comments
 (0)