Skip to content

Commit

Permalink
Update internal docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil committed Nov 18, 2024
1 parent 2016d5e commit a62ed10
Showing 1 changed file with 31 additions and 28 deletions.
59 changes: 31 additions & 28 deletions esmerald/security/http/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,16 @@ class HTTPBasic(HTTPBase):
Example:
```python
from typing import Annotated
from fastapi import Depends, FastAPI
from fastapi.security import HTTPBasic, HTTPBasicCredentials
from typing import Any
from esmerald import Gateway, Inject, Injects, get
from esmerald.security.http import HTTPBasic, HTTPBasicCredentials
from esmerald.testclient import create_client
app = FastAPI()
security = HTTPBasic()
@app.get("/users/me")
def read_current_user(credentials: Annotated[HTTPBasicCredentials, Depends(security)]):
@app.get("/users/me", security=[security], dependencies={"credentials": Inject(security)}))
def read_current_user(credentials: HTTPBasicCredentials = Injects()):
return {"username": credentials.username, "password": credentials.password}
```
"""
Expand Down Expand Up @@ -163,19 +164,20 @@ class HTTPBearer(HTTPBase):
Use this class as a dependency to enforce HTTP Bearer token authentication.
Example:
```python
from typing import Annotated
from fastapi import Depends, FastAPI
from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer
## Example
app = FastAPI()
security = HTTPBearer()
```python
from typing import Any
@app.get("/users/me")
def read_current_user(credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)]):
return {"scheme": credentials.scheme, "credentials": credentials.credentials}
```
from esmerald import Inject, Injects, get
from esmerald.security.http import HTTPAuthorizationCredentials, HTTPBearer
security = HTTPBearer()
@app.get("/users/me")
def read_current_user(credentials: HTTPAuthorizationCredentials = Injects()) -> Any::
return {"scheme": credentials.scheme, "credentials": credentials.credentials}
```
"""

def __init__(
Expand Down Expand Up @@ -224,19 +226,20 @@ class HTTPDigest(HTTPBase):
Use this class as a dependency to enforce HTTP Digest authentication.
Example:
```python
from typing import Annotated
from fastapi import Depends, FastAPI
from fastapi.security import HTTPAuthorizationCredentials, HTTPDigest
## Example:
app = FastAPI()
security = HTTPDigest()
```python
from typing import Any
@app.get("/users/me")
def read_current_user(credentials: Annotated[HTTPAuthorizationCredentials, Depends(security)]):
return {"scheme": credentials.scheme, "credentials": credentials.credentials}
```
from esmerald import Inject, Injects, get
from esmerald.security.http import HTTPAuthorizationCredentials, HTTPDigest
security = HTTPDigest()
@get("/users/me", security=[security], dependencies={"credentials": Inject(security)})
def read_current_user(credentials: HTTPAuthorizationCredentials = Injects()) -> Any:
return {"scheme": credentials.scheme, "credentials": credentials.credentials}
```
"""

def __init__(
Expand Down

0 comments on commit a62ed10

Please sign in to comment.