oauth2.py — fastapi Source File
Architecture documentation for oauth2.py, a python file in the fastapi codebase. 15 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR efdd0530_d49f_83d3_f1d5_e8884b1b9602["oauth2.py"] 0dda2280_3359_8460_301c_e98c77e78185["typing"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> 0dda2280_3359_8460_301c_e98c77e78185 5efacb44_5373_ceb9_9579_6e6603820488["annotated_doc"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> 5efacb44_5373_ceb9_9579_6e6603820488 01c652c5_d85c_f45e_848e_412c94ea4172["exceptions.py"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> 01c652c5_d85c_f45e_848e_412c94ea4172 53e07af2_3e5c_ea1f_ee6c_abc9792bf48b["HTTPException"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> 53e07af2_3e5c_ea1f_ee6c_abc9792bf48b 7f688779_6b22_3c15_6514_97dec91c3c30["models.py"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> 7f688779_6b22_3c15_6514_97dec91c3c30 f0e2889d_18fe_8d6f_c8d5_f009c8384bc4["OAuth2"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> f0e2889d_18fe_8d6f_c8d5_f009c8384bc4 a6e13c71_467d_43e1_dc2b_ae1d7b859051["OAuthFlows"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> a6e13c71_467d_43e1_dc2b_ae1d7b859051 24a9a43e_697f_81ce_6a7c_28a423a6f93b["param_functions.py"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> 24a9a43e_697f_81ce_6a7c_28a423a6f93b a04eddc5_a187_664a_d781_fb175fd636d5["Form"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> a04eddc5_a187_664a_d781_fb175fd636d5 81864ff4_3194_3d8a_0ac8_a6193fbdc833["base.py"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> 81864ff4_3194_3d8a_0ac8_a6193fbdc833 1aa22226_1c87_90b6_c61d_502d10cd0315["SecurityBase"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> 1aa22226_1c87_90b6_c61d_502d10cd0315 de19417f_f5be_8d95_6a5d_91ed8317a398["utils.py"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> de19417f_f5be_8d95_6a5d_91ed8317a398 21dea0a2_f30d_d3da_ce48_734fa9836d52["get_authorization_scheme_param"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> 21dea0a2_f30d_d3da_ce48_734fa9836d52 7ba41d57_5222_3320_290a_ff23f8a854b4["starlette.requests"] efdd0530_d49f_83d3_f1d5_e8884b1b9602 --> 7ba41d57_5222_3320_290a_ff23f8a854b4 style efdd0530_d49f_83d3_f1d5_e8884b1b9602 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
from typing import Annotated, Any, Optional, Union, cast
from annotated_doc import Doc
from fastapi.exceptions import HTTPException
from fastapi.openapi.models import OAuth2 as OAuth2Model
from fastapi.openapi.models import OAuthFlows as OAuthFlowsModel
from fastapi.param_functions import Form
from fastapi.security.base import SecurityBase
from fastapi.security.utils import get_authorization_scheme_param
from starlette.requests import Request
from starlette.status import HTTP_401_UNAUTHORIZED
class 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.
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.
"""
def __init__(
self,
// ... (634 more lines)
Domain
Subdomains
Classes
Dependencies
- Form
- HTTPException
- OAuth2
- OAuthFlows
- SecurityBase
- annotated_doc
- base.py
- exceptions.py
- get_authorization_scheme_param
- models.py
- param_functions.py
- starlette.requests
- starlette.status
- typing
- utils.py
Source
Frequently Asked Questions
What does oauth2.py do?
oauth2.py is a source file in the fastapi codebase, written in python. It belongs to the Security domain, Schemes subdomain.
What does oauth2.py depend on?
oauth2.py imports 15 module(s): Form, HTTPException, OAuth2, OAuthFlows, SecurityBase, annotated_doc, base.py, exceptions.py, and 7 more.
What files import oauth2.py?
oauth2.py is imported by 2 file(s): __init__.py, utils.py.
Where is oauth2.py in the architecture?
oauth2.py is located at fastapi/security/oauth2.py (domain: Security, subdomain: Schemes, directory: fastapi/security).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free