From 2ee92aefe80b7182a43212aea5271f1098005fd2 Mon Sep 17 00:00:00 2001 From: Mark Gascoyne Date: Thu, 2 Apr 2026 08:18:38 +0100 Subject: [PATCH] fix: use KrakenAuthMixin for email/password auth even when OAuthMixin is present MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When both oauth_mixin.py and kraken_auth_mixin.py are available (as in the standard release), the auth init logic unconditionally preferred OAuthMixin. But OAuthMixin has no email/password support — it sets access_token=None and check_and_refresh_oauth_token() returns True without obtaining a token, causing "No access token for find-tariffs". Now prefer KrakenAuthMixin when auth_method is "email" or "api_key", falling back to OAuthMixin only for SaaS OAuth mode. Fixes #3681 Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/predbat/kraken.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/apps/predbat/kraken.py b/apps/predbat/kraken.py index 523c6aaab..774d958f7 100644 --- a/apps/predbat/kraken.py +++ b/apps/predbat/kraken.py @@ -130,8 +130,12 @@ def initialize( if export_account_id or export_mpan: self.log(f"Kraken: Export account configured — {export_account_id or 'same account'} MPAN {export_mpan or 'auto'}") - # Init auth — OAuthMixin or KrakenAuthMixin depending on import - if hasattr(self, "_init_oauth") and hasattr(_AUTH_BASE, "_init_oauth") and not hasattr(_AUTH_BASE, "_init_kraken_auth"): + # Init auth — prefer KrakenAuthMixin for local email/password or API key auth, + # use OAuthMixin only for SaaS OAuth mode (where tokens come from edge functions). + use_local_auth = auth_method in ("email", "api_key") and hasattr(self, "_init_kraken_auth") + if use_local_auth: + self._init_kraken_auth(auth_method, key=key, email=email, password=password) + elif hasattr(self, "_init_oauth"): self._init_oauth(auth_method, key, token_expires_at, "kraken") self.token_hash = token_hash or "" elif hasattr(self, "_init_kraken_auth"):