Skip to main content

OAuth2PasswordRequestForm

This is a dependency class to collect the username and password as form data for an OAuth2 password flow. The OAuth2 specification dictates that for a password flow the data should be collected using form data (instead of JSON) and that it should have the specific fields username and password. All the initialization parameters are extracted from the request.

Attributes

AttributeTypeDescription
grant_type`strNone` = None
usernamestrusername string. The OAuth2 spec requires the exact field name username.
passwordstrpassword string. The OAuth2 spec requires the exact field name password.
scopeslist[str] = ''A single string with actually several scopes separated by spaces. Each scope is also a string.
client_id`strNone` = None
client_secret`strNone` = None

Constructor

Signature

def OAuth2PasswordRequestForm(
grant_type: str | None = None,
username: str = null,
password: str = null,
scope: str = "",
client_id: str | None = None,
client_secret: str | None = None
) - > null

Parameters

NameTypeDescription
grant_type`strNone` = None
usernamestr = nullusername string. The OAuth2 spec requires the exact field name username. Read more about it in the FastAPI docs for Simple OAuth2 with Password and Bearer.
passwordstr = nullpassword string. The OAuth2 spec requires the exact field name password. Read more about it in the FastAPI docs for Simple OAuth2 with Password and Bearer.
scopestr = ""A single string with actually several scopes separated by spaces. Each scope is also a string. For example, a single string with: ```python "items:read items:write users:read profile openid" ```` would represent the scopes: * items:read * items:write * users:read * profile * openid Read more about it in the FastAPI docs for Simple OAuth2 with Password and Bearer.
client_id`strNone` = None
client_secret`strNone` = None

Signature

def OAuth2PasswordRequestForm(
grant_type: str | None = None,
username: str,
password: str,
scope: str = "",
client_id: str | None = None,
client_secret: str | None = None
) - > null

Parameters

NameTypeDescription
grant_type`strNone` = None
usernamestrusername string. The OAuth2 spec requires the exact field name username.
passwordstrpassword string. The OAuth2 spec requires the exact field name password.
scopestr = ""A single string with actually several scopes separated by spaces. Each scope is also a string. For example, a single string with: python "items:read items:write users:read profile openid" would represent the scopes: * items:read * items:write * users:read * profile * openid
client_id`strNone` = None
client_secret`strNone` = None