Skip to content

Commit

Permalink
docs: add cookie example in README.md (#9)
Browse files Browse the repository at this point in the history
Co-authored-by: Konstantin Chernyshev <[email protected]>
  • Loading branch information
Sebsebzen and k4black authored Mar 4, 2023
1 parent d8151e4 commit 611d277
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,27 @@ pip install fastapi-jwt
This library made in fastapi style, so it can be used as standard security features

```python
from fastapi import FastAPI, Security
from fastapi import FastAPI, Security, Response
from fastapi_jwt import JwtAuthorizationCredentials, JwtAccessBearer


app = FastAPI()
access_security = JwtAccessBearer(secret_key="secret_key", auto_error=True)


@app.post("/auth")
def auth():
subject = {"username": "username", "role": "user"}
return {"access_token": access_security.create_access_token(subject=subject)}

@app.post("/auth_cookie")
def auth(response: Response):
subject = {"username": "username", "role": "user"}
access_token = access_security.create_access_token(subject=subject)
access_security.set_access_cookie(response, access_token)
return {"access_token": access_token}


@app.get("/users/me")
def read_current_user(
credentials: JwtAuthorizationCredentials = Security(access_security),
Expand Down

0 comments on commit 611d277

Please sign in to comment.