Remove oauth2client dependency in Google Sheets (#85637)

Remove oauth2client dependency
This commit is contained in:
Robert Hillis 2023-01-11 22:02:02 -05:00 committed by GitHub
parent 0ae855d345
commit ae9a57b2a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 18 deletions

View File

@ -1,6 +1,4 @@
"""application_credentials platform for Google Sheets.""" """application_credentials platform for Google Sheets."""
import oauth2client
from homeassistant.components.application_credentials import AuthorizationServer from homeassistant.components.application_credentials import AuthorizationServer
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
@ -8,17 +6,15 @@ from homeassistant.core import HomeAssistant
async def async_get_authorization_server(hass: HomeAssistant) -> AuthorizationServer: async def async_get_authorization_server(hass: HomeAssistant) -> AuthorizationServer:
"""Return authorization server.""" """Return authorization server."""
return AuthorizationServer( return AuthorizationServer(
oauth2client.GOOGLE_AUTH_URI, "https://accounts.google.com/o/oauth2/v2/auth",
oauth2client.GOOGLE_TOKEN_URI, "https://oauth2.googleapis.com/token",
) )
async def async_get_description_placeholders(hass: HomeAssistant) -> dict[str, str]: async def async_get_description_placeholders(hass: HomeAssistant) -> dict[str, str]:
"""Return description placeholders for the credentials dialog.""" """Return description placeholders for the credentials dialog."""
return { return {
"oauth_consent_url": ( "oauth_consent_url": "https://console.cloud.google.com/apis/credentials/consent",
"https://console.cloud.google.com/apis/credentials/consent"
),
"more_info_url": "https://www.home-assistant.io/integrations/google_sheets/", "more_info_url": "https://www.home-assistant.io/integrations/google_sheets/",
"oauth_creds_url": "https://console.cloud.google.com/apis/credentials", "oauth_creds_url": "https://console.cloud.google.com/apis/credentials",
} }

View File

@ -4,7 +4,6 @@ from collections.abc import Generator
from unittest.mock import Mock, patch from unittest.mock import Mock, patch
from gspread import GSpreadException from gspread import GSpreadException
import oauth2client
import pytest import pytest
from homeassistant import config_entries from homeassistant import config_entries
@ -21,6 +20,8 @@ from tests.common import MockConfigEntry
CLIENT_ID = "1234" CLIENT_ID = "1234"
CLIENT_SECRET = "5678" CLIENT_SECRET = "5678"
GOOGLE_AUTH_URI = "https://accounts.google.com/o/oauth2/v2/auth"
GOOGLE_TOKEN_URI = "https://oauth2.googleapis.com/token"
SHEET_ID = "google-sheet-id" SHEET_ID = "google-sheet-id"
TITLE = "Google Sheets" TITLE = "Google Sheets"
@ -66,7 +67,7 @@ async def test_full_flow(
) )
assert result["url"] == ( assert result["url"] == (
f"{oauth2client.GOOGLE_AUTH_URI}?response_type=code&client_id={CLIENT_ID}" f"{GOOGLE_AUTH_URI}?response_type=code&client_id={CLIENT_ID}"
"&redirect_uri=https://example.com/auth/external/callback" "&redirect_uri=https://example.com/auth/external/callback"
f"&state={state}&scope=https://www.googleapis.com/auth/drive.file" f"&state={state}&scope=https://www.googleapis.com/auth/drive.file"
"&access_type=offline&prompt=consent" "&access_type=offline&prompt=consent"
@ -83,7 +84,7 @@ async def test_full_flow(
mock_client.return_value.create = mock_create mock_client.return_value.create = mock_create
aioclient_mock.post( aioclient_mock.post(
oauth2client.GOOGLE_TOKEN_URI, GOOGLE_TOKEN_URI,
json={ json={
"refresh_token": "mock-refresh-token", "refresh_token": "mock-refresh-token",
"access_token": "mock-access-token", "access_token": "mock-access-token",
@ -133,7 +134,7 @@ async def test_create_sheet_error(
) )
assert result["url"] == ( assert result["url"] == (
f"{oauth2client.GOOGLE_AUTH_URI}?response_type=code&client_id={CLIENT_ID}" f"{GOOGLE_AUTH_URI}?response_type=code&client_id={CLIENT_ID}"
"&redirect_uri=https://example.com/auth/external/callback" "&redirect_uri=https://example.com/auth/external/callback"
f"&state={state}&scope=https://www.googleapis.com/auth/drive.file" f"&state={state}&scope=https://www.googleapis.com/auth/drive.file"
"&access_type=offline&prompt=consent" "&access_type=offline&prompt=consent"
@ -150,7 +151,7 @@ async def test_create_sheet_error(
mock_client.return_value.create = mock_create mock_client.return_value.create = mock_create
aioclient_mock.post( aioclient_mock.post(
oauth2client.GOOGLE_TOKEN_URI, GOOGLE_TOKEN_URI,
json={ json={
"refresh_token": "mock-refresh-token", "refresh_token": "mock-refresh-token",
"access_token": "mock-access-token", "access_token": "mock-access-token",
@ -202,7 +203,7 @@ async def test_reauth(
}, },
) )
assert result["url"] == ( assert result["url"] == (
f"{oauth2client.GOOGLE_AUTH_URI}?response_type=code&client_id={CLIENT_ID}" f"{GOOGLE_AUTH_URI}?response_type=code&client_id={CLIENT_ID}"
"&redirect_uri=https://example.com/auth/external/callback" "&redirect_uri=https://example.com/auth/external/callback"
f"&state={state}&scope=https://www.googleapis.com/auth/drive.file" f"&state={state}&scope=https://www.googleapis.com/auth/drive.file"
"&access_type=offline&prompt=consent" "&access_type=offline&prompt=consent"
@ -218,7 +219,7 @@ async def test_reauth(
mock_client.return_value.open_by_key = mock_open mock_client.return_value.open_by_key = mock_open
aioclient_mock.post( aioclient_mock.post(
oauth2client.GOOGLE_TOKEN_URI, GOOGLE_TOKEN_URI,
json={ json={
"refresh_token": "mock-refresh-token", "refresh_token": "mock-refresh-token",
"access_token": "updated-access-token", "access_token": "updated-access-token",
@ -283,7 +284,7 @@ async def test_reauth_abort(
}, },
) )
assert result["url"] == ( assert result["url"] == (
f"{oauth2client.GOOGLE_AUTH_URI}?response_type=code&client_id={CLIENT_ID}" f"{GOOGLE_AUTH_URI}?response_type=code&client_id={CLIENT_ID}"
"&redirect_uri=https://example.com/auth/external/callback" "&redirect_uri=https://example.com/auth/external/callback"
f"&state={state}&scope=https://www.googleapis.com/auth/drive.file" f"&state={state}&scope=https://www.googleapis.com/auth/drive.file"
"&access_type=offline&prompt=consent" "&access_type=offline&prompt=consent"
@ -300,7 +301,7 @@ async def test_reauth_abort(
mock_client.return_value.open_by_key = mock_open mock_client.return_value.open_by_key = mock_open
aioclient_mock.post( aioclient_mock.post(
oauth2client.GOOGLE_TOKEN_URI, GOOGLE_TOKEN_URI,
json={ json={
"refresh_token": "mock-refresh-token", "refresh_token": "mock-refresh-token",
"access_token": "updated-access-token", "access_token": "updated-access-token",
@ -346,7 +347,7 @@ async def test_already_configured(
) )
assert result["url"] == ( assert result["url"] == (
f"{oauth2client.GOOGLE_AUTH_URI}?response_type=code&client_id={CLIENT_ID}" f"{GOOGLE_AUTH_URI}?response_type=code&client_id={CLIENT_ID}"
"&redirect_uri=https://example.com/auth/external/callback" "&redirect_uri=https://example.com/auth/external/callback"
f"&state={state}&scope=https://www.googleapis.com/auth/drive.file" f"&state={state}&scope=https://www.googleapis.com/auth/drive.file"
"&access_type=offline&prompt=consent" "&access_type=offline&prompt=consent"
@ -363,7 +364,7 @@ async def test_already_configured(
mock_client.return_value.create = mock_create mock_client.return_value.create = mock_create
aioclient_mock.post( aioclient_mock.post(
oauth2client.GOOGLE_TOKEN_URI, GOOGLE_TOKEN_URI,
json={ json={
"refresh_token": "mock-refresh-token", "refresh_token": "mock-refresh-token",
"access_token": "mock-access-token", "access_token": "mock-access-token",