Repository: home-assistant/core
File: homeassistant/helpers/config_entry_oauth2_flow.py (Python)

Code before:
            URL(self.authorize_url)
            .with_query(
                {
                    "response_type": "code",
                    "client_id": self.client_id,
                    "redirect_uri": redirect_uri,
                    "state": _encode_jwt(
                        self.hass, {"flow_id": flow_id, "redirect_uri": redirect_uri}
                    ),
                }
            )
            .update_query(self.extra_authorize_data)
        )

    async def async_resolve_external_data(self, external_data: Any) -> dict:
        """Resolve the authorization code to tokens."""
        request_data: dict = {
            "grant_type": "authorization_code",
            "code": external_data["code"],
            "redirect_uri": external_data["state"]["redirect_uri"],
        }
        request_data.update(self.extra_token_resolve_data)
        return await self._token_request(request_data)

    async def _async_refresh_token(self, token: dict) -> dict:
        """Refresh a token. Raises OAuth2RefreshTokenFailed on failure."""
        try:
            new_token = await self._token_request(
                {
                    "grant_type": "refresh_token",
                    "client_id": self.client_id,
                    "refresh_token": token["refresh_token"],
                }
            )
        except ClientResponseError as err:
            # Store the warning messages in memory during Home Assistant runtime
            # This to prevent spamming for logs who are not ready, yet
            you_are_warned: set[str] = self.hass.data.setdefault(
                DATA_OAUTH2_REFRESHTOKEN_DEPRECATION_WARNING, set()
            )

            # Best what I could to think of is to use the clientID, unique enough to prevent flooding?
            # I don't have config_entry available. If correct, you have a client ID per config entry
            if self.client_id not in you_are_warned:
                _LOGGER.warning(
                    "Refresh token failed. Please catch 'OAuth2RefreshTokenFailed'. This will be added in version 2026.x.x and result in a breaking change"
                )
                you_are_warned.add(self.client_id)

            raise OAuth2RefreshTokenFailed(
                request_info=err.request_info,

Review comment (bug):
```suggestion
        """Refresh a token.

        Raises OAuth2RefreshTokenFailed on token refresh failure.
        """
```

Code after:

    async def async_generate_authorize_url(self, flow_id: str) -> str:
        """Generate a url for the user to authorize."""
        redirect_uri = self.redirect_uri
        return str(
            URL(self.authorize_url)
            .with_query(
                {
                    "response_type": "code",
                    "client_id": self.client_id,
                    "redirect_uri": redirect_uri,
                    "state": _encode_jwt(
                        self.hass, {"flow_id": flow_id, "redirect_uri": redirect_uri}
                    ),
                }
            )
            .update_query(self.extra_authorize_data)
        )

    async def async_resolve_external_data(self, external_data: Any) -> dict:
        """Resolve the authorization code to tokens."""
        request_data: dict = {
            "grant_type": "authorization_code",
            "code": external_data["code"],
            "redirect_uri": external_data["state"]["redirect_uri"],
        }
        request_data.update(self.extra_token_resolve_data)
        return await self._token_request(request_data)

    async def _async_refresh_token(self, token: dict) -> dict:
        """Refresh a token."""

        new_token = await self._token_request(
            {
                "grant_type": "refresh_token",
                "client_id": self.client_id,
                "refresh_token": token["refresh_token"],
            }
        )

        return {**token, **new_token}

    async def _token_request(self, data: dict) -> dict:
        """Make a token request.

        Raises OAuth2TokenRequestError on token request failure.
        """
        session = async_get_clientsession(self.hass)

        data["client_id"] = self.client_id
        if self.client_secret: