Skip to content

Commit e0ca1d4

Browse files
committed
GH-36: Memorize access_token property
1 parent 3edfeb8 commit e0ca1d4

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/fastapi_oauth2/core.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class OAuth2Core:
5454
_oauth_client: Optional[WebApplicationClient] = None
5555
_authorization_endpoint: str = None
5656
_token_endpoint: str = None
57+
_access_token: str = None
5758
_state: str = None
5859

5960
def __init__(self, client: OAuth2Client) -> None:
@@ -70,7 +71,9 @@ def __init__(self, client: OAuth2Client) -> None:
7071

7172
@property
7273
def access_token(self) -> str:
73-
return self._oauth_client.access_token
74+
if not self._access_token:
75+
self._access_token = self._oauth_client.access_token
76+
return self._access_token
7477

7578
def get_redirect_uri(self, request: Request) -> str:
7679
return urljoin(str(request.base_url), "/oauth2/%s/token" % self.provider)

0 commit comments

Comments
 (0)