Maxime Grenu 1 month ago
committed by GitHub
parent
commit
944a82d58f
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 4
      fastapi/security/oauth2.py
  2. 7
      tests/test_security_oauth2.py
  3. 7
      tests/test_security_oauth2_optional.py
  4. 7
      tests/test_security_oauth2_optional_description.py

4
fastapi/security/oauth2.py

@ -255,7 +255,7 @@ class OAuth2PasswordRequestFormStrict(OAuth2PasswordRequestForm):
], ],
password: Annotated[ password: Annotated[
str, str,
Form(), Form(json_schema_extra={"format": "password"}),
Doc( Doc(
""" """
`password` string. The OAuth2 spec requires the exact field name `password` string. The OAuth2 spec requires the exact field name
@ -306,7 +306,7 @@ class OAuth2PasswordRequestFormStrict(OAuth2PasswordRequestForm):
] = None, ] = None,
client_secret: Annotated[ client_secret: Annotated[
str | None, str | None,
Form(), Form(json_schema_extra={"format": "password"}),
Doc( Doc(
""" """
If there's a `client_secret` (and a `client_id`), they can be sent If there's a `client_secret` (and a `client_id`), they can be sent

7
tests/test_security_oauth2.py

@ -213,7 +213,11 @@ def test_openapi_schema():
"type": "string", "type": "string",
}, },
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
"password": {"title": "Password", "type": "string"}, "password": {
"title": "Password",
"type": "string",
"format": "password",
},
"scope": { "scope": {
"title": "Scope", "title": "Scope",
"type": "string", "type": "string",
@ -226,6 +230,7 @@ def test_openapi_schema():
"client_secret": { "client_secret": {
"title": "Client Secret", "title": "Client Secret",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"format": "password",
}, },
}, },
}, },

7
tests/test_security_oauth2_optional.py

@ -214,7 +214,11 @@ def test_openapi_schema():
"type": "string", "type": "string",
}, },
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
"password": {"title": "Password", "type": "string"}, "password": {
"title": "Password",
"type": "string",
"format": "password",
},
"scope": { "scope": {
"title": "Scope", "title": "Scope",
"type": "string", "type": "string",
@ -227,6 +231,7 @@ def test_openapi_schema():
"client_secret": { "client_secret": {
"title": "Client Secret", "title": "Client Secret",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"format": "password",
}, },
}, },
}, },

7
tests/test_security_oauth2_optional_description.py

@ -215,7 +215,11 @@ def test_openapi_schema():
"type": "string", "type": "string",
}, },
"username": {"title": "Username", "type": "string"}, "username": {"title": "Username", "type": "string"},
"password": {"title": "Password", "type": "string"}, "password": {
"title": "Password",
"type": "string",
"format": "password",
},
"scope": { "scope": {
"title": "Scope", "title": "Scope",
"type": "string", "type": "string",
@ -228,6 +232,7 @@ def test_openapi_schema():
"client_secret": { "client_secret": {
"title": "Client Secret", "title": "Client Secret",
"anyOf": [{"type": "string"}, {"type": "null"}], "anyOf": [{"type": "string"}, {"type": "null"}],
"format": "password",
}, },
}, },
}, },

Loading…
Cancel
Save