Skip to content

Commit c7ca1ce

Browse files
Fix access token caching issue on login (GH-48)
Co-authored-by: Harpo Harbert <[email protected]>
2 parents 53973d6 + 11eff9d commit c7ca1ce

File tree

2 files changed

+2
-54
lines changed

2 files changed

+2
-54
lines changed

Diff for: docs/references/tutorials.md

+1-50
Original file line numberDiff line numberDiff line change
@@ -28,31 +28,6 @@ generated the client ID and secret to configure your `OAuth2Middleware` with at
2828
Once the authentication is successful, the user will be redirected to the `redirect_uri` and the `request.user` will
2929
contain the user information obtained from the IDP.
3030

31-
## Access token
32-
33-
When the user is authenticated, the `request.user` will contain the user information obtained from the IDP and
34-
the `request.auth` will contain the authentication related information including the access token issued by the IDP. It
35-
can be used to perform authorized requests to the IDP's API endpoints. Just make sure the token is issued with the
36-
scopes required for the API endpoint.
37-
38-
::: details `request.auth.provider.access_token`
39-
40-
```mermaid
41-
flowchart TB
42-
subgraph level2["request (Starlette's Request object)"]
43-
direction TB
44-
subgraph level1["auth (Starlette's extended Auth Credentials)"]
45-
direction TB
46-
subgraph level0["provider (OAuth2 provider with client's credentials)"]
47-
direction TB
48-
token["access_token (Access token for the specified scopes)"]
49-
end
50-
end
51-
end
52-
```
53-
54-
:::
55-
5631
## Claims mapping
5732

5833
The `Claims` class includes permanent attributes like `display_name`, `identity`, `picture`, and `email`. It also allows
@@ -150,31 +125,7 @@ The request is considered invalid when one of the mandatory parameters, such as
150125
request fails. And the errors that occur during the OAuth steps are considered authentication errors.
151126

152127
<style>
153-
.info, .details {
128+
.info {
154129
border: 0;
155130
}
156-
157-
g#level2 rect,
158-
g#level1 rect,
159-
g#level0 rect,
160-
g[id^="flowchart-token"] rect {
161-
color: #f6f6f7 !important;
162-
stroke: #3c3c43 !important;
163-
}
164-
165-
g#level2 rect {
166-
fill: #00948680 !important;
167-
}
168-
169-
g#level1 rect {
170-
fill: #2b75a080 !important;
171-
}
172-
173-
g#level0 rect {
174-
fill: #5c837480 !important;
175-
}
176-
177-
g[id^="flowchart-token"] rect {
178-
fill: #44506980 !important;
179-
}
180131
</style>

Diff for: src/fastapi_oauth2/core.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ class OAuth2Core:
5454
_oauth_client: Optional[WebApplicationClient] = None
5555
_authorization_endpoint: str = None
5656
_token_endpoint: str = None
57-
_access_token: str = None
5857
_state: str = None
5958

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

7271
@property
7372
def access_token(self) -> str:
74-
if not self._access_token:
75-
self._access_token = self._oauth_client.access_token
76-
return self._access_token
73+
return self._oauth_client.access_token
7774

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

0 commit comments

Comments
 (0)