33import asyncio
44import json
55import time
6+ from typing import override
67
78import grpc
89import httpx
@@ -22,11 +23,13 @@ def __init__(self, token: str) -> None:
2223 """Initialize the plugin with the auth token.
2324
2425 Args:
26+ ----
2527 token: The authorization token to add to requests
2628
2729 """
28- self ._token = token
30+ self ._token : str = token
2931
32+ @override
3033 def __call__ (
3134 self ,
3235 _ : grpc .AuthMetadataContext ,
@@ -37,6 +40,7 @@ def __call__(
3740 This method will be invoked asynchronously in a separate thread.
3841
3942 Args:
43+ ----
4044 callback: An AuthMetadataPluginCallback to be invoked either
4145 synchronously or asynchronously.
4246
@@ -58,6 +62,7 @@ def __init__(
5862 """Initialize the credential helper.
5963
6064 Args:
65+ ----
6166 client_id: OAuth client ID
6267 client_secret: OAuth client secret
6368 auth_url: OAuth token endpoint URL
@@ -71,24 +76,26 @@ def __init__(
7176 msg = "client_secret cannot be empty"
7277 raise CredentialError (msg )
7378
74- self ._client_id = client_id
75- self ._client_secret = client_secret
76- self ._auth_url = auth_url
77- self ._audience = audience
79+ self ._client_id : str = client_id
80+ self ._client_secret : str = client_secret
81+ self ._auth_url : str = auth_url
82+ self ._audience : str = audience
7883 self ._token : str | None = None
7984 self ._token_expires_at : float | None = None
80- self ._lock = asyncio .Lock ()
85+ self ._lock : asyncio . Lock = asyncio .Lock ()
8186
8287 async def get_token (self ) -> str :
8388 """Get a valid authentication token.
8489
8590 This method will return a cached token if it's still valid,
8691 or fetch a new token if needed.
8792
88- Returns:
93+ Returns
94+ -------
8995 A valid authentication token
9096
91- Raises:
97+ Raises
98+ ------
9299 OAuthError: If token acquisition fails
93100 TokenExpiredError: If token has expired and refresh fails
94101
@@ -109,7 +116,8 @@ async def get_token(self) -> str:
109116 def _is_token_valid (self ) -> bool :
110117 """Check if the current token is valid and not expired.
111118
112- Returns:
119+ Returns
120+ -------
113121 True if token is valid, False otherwise
114122
115123 """
@@ -122,7 +130,8 @@ def _is_token_valid(self) -> bool:
122130 async def _refresh_token (self ) -> None :
123131 """Refresh the authentication token by making an OAuth request.
124132
125- Raises:
133+ Raises
134+ ------
126135 OAuthError: If the OAuth request fails
127136
128137 """
@@ -143,7 +152,7 @@ async def _refresh_token(self) -> None:
143152 headers = headers ,
144153 timeout = 30.0 ,
145154 )
146- response .raise_for_status ()
155+ _ = response .raise_for_status ()
147156
148157 token_data = response .json ()
149158 self ._token = token_data ["access_token" ]
@@ -195,13 +204,16 @@ async def create_channel_with_credentials(
195204 """Create a gRPC channel with OAuth credential helper.
196205
197206 Args:
207+ ----
198208 host: The host address to connect to
199209 credential_helper: The credential helper for OAuth authentication
200210
201211 Returns:
212+ -------
202213 A secure gRPC channel with OAuth authentication
203214
204215 Raises:
216+ ------
205217 InvalidHostError: If host is empty
206218 OAuthError: If OAuth authentication fails
207219
0 commit comments