ruạṛ
a �u:j � @ s� d dl mZmZmZmZmZ d dlmZ d dlm Z d dlmZ d dl mZ d dlmZ d dlmZ d dlmZ d d lmZmZ G d d� d�ZG dd � d e�ZG dd� de�Z G dd� de �ZG dd� de �ZG dd� d�ZdS )� )�Any�Dict�List�Optional�Union)� HTTPException)�OAuth2)� OAuthFlows)�Form)�SecurityBase)�get_authorization_scheme_param)�Request)�HTTP_401_UNAUTHORIZED�HTTP_403_FORBIDDENc @ s\ e Zd ZdZeddd�e� e� edd�edd�edd�feeeeee ee d�dd �ZdS ) �OAuth2PasswordRequestForma� This is a dependency class, use it like: @app.post("/login") def login(form_data: OAuth2PasswordRequestForm = Depends()): data = form_data.parse() print(data.username) print(data.password) for scope in data.scopes: print(scope) if data.client_id: print(data.client_id) if data.client_secret: print(data.client_secret) return data It creates the following Form request parameters in your endpoint: grant_type: the OAuth2 spec says it is required and MUST be the fixed string "password". Nevertheless, this dependency class is permissive and allows not passing it. If you want to enforce it, use instead the OAuth2PasswordRequestFormStrict dependency. username: username string. The OAuth2 spec requires the exact field name "username". password: password string. The OAuth2 spec requires the exact field name "password". scope: Optional string. Several scopes (each one a string) separated by spaces. E.g. "items:read items:write users:read profile openid" client_id: optional string. OAuth2 recommends sending the client_id and client_secret (if any) using HTTP Basic auth, as: client_id:client_secret client_secret: optional string. OAuth2 recommends sending the client_id and client_secret (if any) using HTTP Basic auth, as: client_id:client_secret N�password)�default�regex� �r �� grant_type�usernamer �scope� client_id� client_secretc C s, || _ || _|| _|�� | _|| _|| _d S )N)r r r �split�scopesr r ��selfr r r r r r � r �J/opt/bart/bart_venv/lib/python3.9/site-packages/fastapi/security/oauth2.py�__init__. s z"OAuth2PasswordRequestForm.__init__)�__name__� __module__�__qualname__�__doc__r �strr r"