2121from podme_api .auth .models import SchibstedCredentials
2222from podme_api .const import (
2323 PODME_AUTH_BASE_URL ,
24+ PODME_AUTH_CLIENT_ID ,
2425 PODME_AUTH_USER_AGENT ,
2526 PODME_BASE_URL ,
2627)
3031 PodMeApiConnectionTimeoutError ,
3132 PodMeApiError ,
3233)
34+ from podme_api .models import PodMeRegion
3335
3436if TYPE_CHECKING :
3537 from podme_api .auth .models import PodMeUserCredentials
3638
3739_LOGGER = logging .getLogger (__name__ )
3840
3941
40- CLIENT_ID = "62557b19f552881812b7431c"
41-
42-
4342@dataclass
4443class PodMeDefaultAuthClient (PodMeAuthClient ):
4544 """Default authentication client for PodMe.
@@ -76,6 +75,9 @@ class PodMeDefaultAuthClient(PodMeAuthClient):
7675 credentials : SchibstedCredentials | None = None
7776 """(SchibstedCredentials | None): Authentication credentials."""
7877
78+ region = PodMeRegion .NO
79+ """(PodMeRegion): The region setting for the client."""
80+
7981 _credentials : SchibstedCredentials | None = field (default = None , init = False )
8082 _close_session : bool = False
8183
@@ -93,6 +95,14 @@ def request_header(self) -> dict[str, str]:
9395 "Referer" : PODME_BASE_URL ,
9496 }
9597
98+ @property
99+ def client_id (self ) -> str :
100+ return PODME_AUTH_CLIENT_ID .get (self .region )
101+
102+ @property
103+ def base_url (self ) -> URL :
104+ return URL (PODME_AUTH_BASE_URL .get (self .region ))
105+
96106 async def _request (
97107 self ,
98108 uri : str ,
@@ -122,7 +132,7 @@ async def _request(
122132
123133 """
124134 if base_url is None :
125- base_url = PODME_AUTH_BASE_URL
135+ base_url = self . base_url
126136 url = URL (base_url ).join (URL (uri ))
127137 headers = {
128138 ** self .request_header ,
@@ -205,8 +215,8 @@ async def authorize(self, user_credentials: PodMeUserCredentials) -> SchibstedCr
205215 response = await self ._request (
206216 "oauth/authorize" ,
207217 params = {
208- "client_id" : CLIENT_ID ,
209- "redirect_uri" : f"pme.podme.{ CLIENT_ID } :/login" ,
218+ "client_id" : self . client_id ,
219+ "redirect_uri" : f"pme.podme.{ self . client_id } :/login" ,
210220 "response_type" : "code" ,
211221 "scope" : "openid offline_access" ,
212222 "state" : hashlib .sha256 (os .urandom (1024 )).hexdigest (),
@@ -222,15 +232,15 @@ async def authorize(self, user_credentials: PodMeUserCredentials) -> SchibstedCr
222232 # Login: step 2/4
223233 response = await self ._request (
224234 "authn/api/settings/csrf" ,
225- params = {"client_id" : CLIENT_ID },
235+ params = {"client_id" : self . client_id },
226236 )
227237 csrf_token = (await response .json ())["data" ]["attributes" ]["csrfToken" ]
228238
229239 # Login: step 3/4
230240 response = await self ._request (
231241 "authn/api/identity/email-status" ,
232242 method = METH_POST ,
233- params = {"client_id" : CLIENT_ID },
243+ params = {"client_id" : self . client_id },
234244 headers = {
235245 "X-CSRF-Token" : csrf_token ,
236246 "Accept" : "application/json" ,
@@ -247,7 +257,7 @@ async def authorize(self, user_credentials: PodMeUserCredentials) -> SchibstedCr
247257 response = await self ._request (
248258 "authn/api/identity/login/" ,
249259 method = METH_POST ,
250- params = {"client_id" : CLIENT_ID },
260+ params = {"client_id" : self . client_id },
251261 headers = {
252262 "X-CSRF-Token" : csrf_token ,
253263 "Accept" : "application/json" ,
@@ -266,7 +276,7 @@ async def authorize(self, user_credentials: PodMeUserCredentials) -> SchibstedCr
266276 response = await self ._request (
267277 "authn/identity/finish/" ,
268278 method = METH_POST ,
269- params = {"client_id" : CLIENT_ID },
279+ params = {"client_id" : self . client_id },
270280 headers = {
271281 "Content-Type" : "application/x-www-form-urlencoded" ,
272282 },
@@ -289,13 +299,13 @@ async def authorize(self, user_credentials: PodMeUserCredentials) -> SchibstedCr
289299 method = METH_POST ,
290300 headers = {
291301 "X-OIDC" : "v1" ,
292- "X-Region" : "NO" , # @TODO: Support multiple regions.
302+ "X-Region" : self . region . name ,
293303 },
294304 data = {
295- "client_id" : CLIENT_ID ,
305+ "client_id" : self . client_id ,
296306 "grant_type" : "authorization_code" ,
297307 "code" : code ,
298- "redirect_uri" : f"pme.podme.{ CLIENT_ID } :/login" ,
308+ "redirect_uri" : f"pme.podme.{ self . client_id } :/login" ,
299309 "code_verifier" : code_verifier ,
300310 },
301311 allow_redirects = False ,
@@ -332,14 +342,14 @@ async def refresh_token(self, credentials: SchibstedCredentials | None = None):
332342 "oauth/token" ,
333343 method = METH_POST ,
334344 headers = {
335- "Host" : "payment.schibsted.no" ,
345+ "Host" : self . base_url . host ,
336346 "Content-Type" : "application/x-www-form-urlencoded" ,
337347 "User-Agent" : "AccountSDKAndroidWeb/6.4.0 (Linux; Android 15; API 35; Google; sdk_gphone64_arm64)" ,
338348 "X-OIDC" : "v1" ,
339- "X-Region" : "NO" , # @TODO: Support multiple regions.
349+ "X-Region" : self . region . name ,
340350 },
341351 data = {
342- "client_id" : CLIENT_ID ,
352+ "client_id" : self . client_id ,
343353 "grant_type" : "refresh_token" ,
344354 "refresh_token" : credentials .refresh_token ,
345355 },
0 commit comments