From f0dc846ea2c0d10aee2427fb3303b28cc221a07f Mon Sep 17 00:00:00 2001 From: Salar Nosrati-Ershad Date: Thu, 18 Apr 2024 18:23:28 +0330 Subject: [PATCH] add refreshurl to OAuth2PasswordBearer --- fastapi/openapi/models.py | 1 + fastapi/security/oauth2.py | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/fastapi/openapi/models.py b/fastapi/openapi/models.py index 5f3bdbb20..eb192f750 100644 --- a/fastapi/openapi/models.py +++ b/fastapi/openapi/models.py @@ -507,6 +507,7 @@ class OAuthFlowImplicit(OAuthFlow): class OAuthFlowPassword(OAuthFlow): tokenUrl: str + refreshUrl: Optional[str] class OAuthFlowClientCredentials(OAuthFlow): diff --git a/fastapi/security/oauth2.py b/fastapi/security/oauth2.py index 9720cace0..7ffb121da 100644 --- a/fastapi/security/oauth2.py +++ b/fastapi/security/oauth2.py @@ -408,6 +408,14 @@ class OAuth2PasswordBearer(OAuth2): """ ), ], + refreshUrl: Annotated[ + Optional[str], + Doc( + """ + The URL to refresh the token and obtain a new one. + """ + ), + ], scheme_name: Annotated[ Optional[str], Doc( @@ -461,7 +469,9 @@ class OAuth2PasswordBearer(OAuth2): if not scopes: scopes = {} flows = OAuthFlowsModel( - password=cast(Any, {"tokenUrl": tokenUrl, "scopes": scopes}) + password=cast( + Any, {"tokenUrl": tokenUrl, "refreshUrl": refreshUrl, "scopes": scopes} + ) ) super().__init__( flows=flows,