From: Salar Nosrati-Ershad Date: Tue, 17 Jun 2025 10:46:49 +0000 (+0330) Subject: ✨ Add `refreshUrl` parameter in `OAuth2PasswordBearer` (#11460) X-Git-Tag: 0.115.13~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=aebff5006fee3f45c634861ccd15885058ba0965;p=thirdparty%2Ffastapi%2Ffastapi.git ✨ Add `refreshUrl` parameter in `OAuth2PasswordBearer` (#11460) Co-authored-by: Salar Nosrati-Ershad Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Alejandra <90076947+alejsdev@users.noreply.github.com> Co-authored-by: Motov Yurii <109919500+YuriiMotov@users.noreply.github.com> --- diff --git a/fastapi/security/oauth2.py b/fastapi/security/oauth2.py index 42ace07a34..88e394db11 100644 --- a/fastapi/security/oauth2.py +++ b/fastapi/security/oauth2.py @@ -457,11 +457,26 @@ class OAuth2PasswordBearer(OAuth2): """ ), ] = True, + refreshUrl: Annotated[ + Optional[str], + Doc( + """ + The URL to refresh the token and obtain a new one. + """ + ), + ] = None, ): 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,