�
K�gQT � �> � d dl mZmZmZmZmZmZ d dlmZ d dl m
Z d dl mZ
d dlmZ d dlmZ d dlmZ d dlmZ d d lmZmZ d d
lmZmZ G d� d� � Z G d
� de� � Z G d� de� � Z
G d� de
� � Z G d� de
� � Z G d� d� � Z dS )� )�Any�Dict�List�Optional�Union�cast)�
HTTPException)�OAuth2)�
OAuthFlows)�Form)�SecurityBase)�get_authorization_scheme_param)�Request)�HTTP_401_UNAUTHORIZED�HTTP_403_FORBIDDEN)� Annotated�Docc � � e Zd ZdZddddd�deeedf ed�� � ed� � f d ee e� � ed
� � f dee e� � ed� � f dee e� � ed
� � f deeedf e� � ed� � f deeedf e� � ed� � f fd�Z dS )�OAuth2PasswordRequestFormaD
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.
Read more about it in the
[FastAPI docs for Simple OAuth2 with Password and Bearer](https://fastapi.tiangolo.com/tutorial/security/simple-oauth2/).
## Example
```python
from typing import Annotated
from fastapi import Depends, FastAPI
from fastapi.security import OAuth2PasswordRequestForm
app = FastAPI()
@app.post("/login")
def login(form_data: Annotated[OAuth2PasswordRequestForm, Depends()]):
data = {}
data["scopes"] = []
for scope in form_data.scopes:
data["scopes"].append(scope)
if form_data.client_id:
data["client_id"] = form_data.client_id
if form_data.client_secret:
data["client_secret"] = form_data.client_secret
return data
```
Note that for OAuth2 the scope `items:read` is a single scope in an opaque string.
You could have custom internal logic to separate it by colon characters (`:`) or
similar, and get the two parts `items` and `read`. Many applications do that to
group and organize permissions, you could do it as well in your application, just
know that that it is application specific, it's not part of the specification.
N� )�
grant_type�scope� client_id�
client_secretr �password��patternaD
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` string. The OAuth2 spec requires the exact field name
`password".
r ��
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`
r ��
If there's a `client_id`, it can be sent as part of the form fields.
But the OAuth2 specification recommends sending the `client_id` and
`client_secret` (if any) using HTTP Basic auth.
r �&
If there's a `client_password` (and a `client_id`), they can be sent
as part of the form fields. But the OAuth2 specification recommends
sending the `client_id` and `client_secret` (if any) using HTTP Basic
auth.
c �~ � || _ || _ || _ |� � � | _ || _ || _ d S �N)r r r �split�scopesr r )�selfr r r r r r s �g/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/fastapi/security/oauth2.py�__init__z"OAuth2PasswordRequestForm.__init__= s>