Results of 1 - 10 of about 10 for secret (0.015 sec.)
- SQL (Relational) Databases 11566
- SQL (Relational) Databases Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . FastAPI doesn't require you to use a SQL (relational) database. But you can use any data
...None , primary_key = True ) name : str = Field ( index = True ) age : int | None = Field ( default = None , index = True ) secret_name : str # Code below omitted ? ? Full file preview Python 3.10+ from typing import Annotated from fastapi import Depend...None , primary_key = True ) name : str = Field ( index = True ) age : int | None = Field ( default = None , index = True ) secret_name : str sqlite_file_name = "database.db" sqlite_url = f "sqlite:/// { sqlite_file_name } " connect_args = { "check_same...mary_key = True ) name : str = Field ( index = True ) age : Union [ int , None ] = Field ( default = None , index = True ) secret_name : str sqlite_file_name = "database.db" sqlite_url = f "sqlite:/// { sqlite_file_name } " connect_args = { "check_same... - https://man.mtool.work/fastapi/0.115/tutorial/sql-databases/
- OAuth2 scopes 10976
- OAuth2 scopes Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . You can use OAuth2 scopes directly with FastAPI , they are integrated to work seamlessly. This would
...port CryptContext from pydantic import BaseModel , ValidationError # to get a string like this run: # openssl rand -hex 32 SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7" ALGORITHM = "HS256" ACCESS_TOKEN_EXPIRE_MINUTES =...zone . utc ) + timedelta ( minutes = 15 ) to_encode . update ({ "exp" : expire }) encoded_jwt = jwt . encode ( to_encode , SECRET_KEY , algorithm = ALGORITHM ) return encoded_jwt async def get_current_user ( security_scopes : SecurityScopes , token : A...ot validate credentials" , headers = { "WWW-Authenticate" : authenticate_value }, ) try : payload = jwt . decode ( token , SECRET_KEY , algorithms = [ ALGORITHM ]) username = payload . get ( "sub" ) if username is None : raise credentials_exception tok... - https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/
- path operationデコレータの依存関係 10833
- path operationデコレータの依存関係 場合によっては path operation関数 の中で依存関係の戻り値を本当に必要としないこともあります。 もしくは、依存関係が値を返さない場合もあります。 しかし、それでも実行・解決する必要があります。 このような場合、
...I , Header , HTTPException app = FastAPI () async def verify_token ( x_token : str = Header ()): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def verify_key ( x_key : str...= Header ()): if x_key != "fake-super-secret-key" : raise HTTPException ( status_code = 400 , detail = "X-Key header invalid" ) return x_key @app . get ( "/items/" , d...HTTPException app = FastAPI () async def verify_token ( x_token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def verify_key ( x_key : Anno... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-in-path-...
- パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer 10583
- パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer これでセキュリティの流れが全てわかったので、 JWT トークンと安全なパスワードのハッシュ化を使用して、実際にアプリケーションを安全にしてみましょう。 このコードは、アプリケーシ
...passlib.context import CryptContext from pydantic import BaseModel # to get a string like this run: # openssl rand -hex 32 SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7" ALGORITHM = "HS256" ACCESS_TOKEN_EXPIRE_MINUTES =...zone . utc ) + timedelta ( minutes = 15 ) to_encode . update ({ "exp" : expire }) encoded_jwt = jwt . encode ( to_encode , SECRET_KEY , algorithm = ALGORITHM ) return encoded_jwt async def get_current_user ( token : str = Depends ( oauth2_scheme )): cr...= "Could not validate credentials" , headers = { "WWW-Authenticate" : "Bearer" }, ) try : payload = jwt . decode ( token , SECRET_KEY , algorithms = [ ALGORITHM ]) username = payload . get ( "sub" ) if username is None : raise credentials_exception tok... - https://man.mtool.work/fastapi/0.115/tutorial/security/oauth2-jwt/
- Global Dependencies 8616
- Global Dependencies Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . For some types of applications you might want to add dependencies to the whole application. Sim
...ng_extensions import Annotated async def verify_token ( x_token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def verify_key ( x_key : Anno...tated [ str , Header ()]): if x_key != "fake-super-secret-key" : raise HTTPException ( status_code = 400 , detail = "X-Key header invalid" ) return x_key app = FastAPI ( dependenci...ng_extensions import Annotated async def verify_token ( x_token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def verify_key ( x_key : Anno... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/global-dependencies/
- テスト 8581
- テスト Starlette のおかげで、 FastAPI アプリケーションのテストは簡単で楽しいものになっています。 HTTPX がベースなので、非常に使いやすく直感的です。 これを使用すると、 FastAPI と共に pytest を直接利用できます。 TestClient を使用 TestClient を
...です。 Python 3.10+ - non-Annotated from fastapi import FastAPI , Header , HTTPException from pydantic import BaseModel fake_secret_token = "coneofsilence" fake_db = { "foo" : { "id" : "foo" , "title" : "Foo" , "description" : "There goes my hero" }, "ba...{item_id} " , response_model = Item ) async def read_main ( item_id : str , x_token : str = Header ()): if x_token != fake_secret_token : raise HTTPException ( status_code = 400 , detail = "Invalid X-Token header" ) if item_id not in fake_db : raise HT...( "/items/" , response_model = Item ) async def create_item ( item : Item , x_token : str = Header ()): if x_token != fake_secret_token : raise HTTPException ( status_code = 400 , detail = "Invalid X-Token header" ) if item . id in fake_db : raise HTTP... - https://man.mtool.work/fastapi/0.115/tutorial/testing/
- モデル - より詳しく 7222
- モデル - より詳しく 先ほどの例に続き、複数の関連モデルを持つことが一般的です。 これはユーザーモデルの場合は特にそうです。なぜなら: 入力モデル にはパスワードが必要です。 出力モデル はパスワードをもつべきではありません。 データベースモデル は
...str email : EmailStr full_name : Union [ str , None ] = None def fake_password_hasher ( raw_password : str ): return "supersecret" + raw_password def fake_save_user ( user_in : UserIn ): hashed_password = fake_password_hasher ( user_in . password ) use...assword : str email : EmailStr full_name : str | None = None def fake_password_hasher ( raw_password : str ): return "supersecret" + raw_password def fake_save_user ( user_in : UserIn ): hashed_password = fake_password_hasher ( user_in . password ) use...あります。 そこで、以下のようなPydanticオブジェクト user_in を作成すると: user_in = UserIn ( username = "john" , password = "secret" , email = "john.doe@example.com" ) そして呼び出すと: user_dict = user_in . dict () これで変数 user_dict のデータを持つ di... - https://man.mtool.work/fastapi/0.115/tutorial/extra-models/
- Bigger Applications - Multiple Files 7151
- Bigger Applications - Multiple Files Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . If you are building an application or a web API, it's rarely the case that you
...ort Header , HTTPException async def get_token_header ( x_token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def get_query_token ( token :...xtensions import Annotated async def get_token_header ( x_token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def get_query_token ( token :...m fastapi import Header , HTTPException async def get_token_header ( x_token : str = Header ()): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 400 , detail = "X-Token header invalid" ) async def get_query_token ( token :... - https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/
- Settings and Environment Variables 6900
- Settings and Environment Variables Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . In many cases your application could need some external settings or configuratio
...ns, for example secret keys, database credentials, credentials for email services, etc. Most of these settings are variable (can change), like da...tabase URLs. And many could be sensitive, like secrets. For this reason it's common to provide them in environment variables that are read by the application. Tip To understand... - https://man.mtool.work/fastapi/0.115/advanced/settings/
- Simple OAuth2 with Password and Bearer 6900
- Simple OAuth2 with Password and Bearer Warning The current page still doesn't have a translation for this language. But you can help translating it: Contributing . Now let's build from the previous chapter and add the missing parts to have
..." : { "username" : "johndoe" , "full_name" : "John Doe" , "email" : "johndoe@example.com" , "hashed_password" : "fakehashedsecret" , "disabled" : False , }, "alice" : { "username" : "alice" , "full_name" : "Alice Wonderson" , "email" : "alice@example.c...om" , "hashed_password" : "fakehashedsecret2" , "disabled" : True , }, } app = FastAPI () def fake_hash_password ( password : str ): return "fakehashed" + password oa..." : { "username" : "johndoe" , "full_name" : "John Doe" , "email" : "johndoe@example.com" , "hashed_password" : "fakehashedsecret" , "disabled" : False , }, "alice" : { "username" : "alice" , "full_name" : "Alice Wonderson" , "email" : "alice@example.c... - https://man.mtool.work/fastapi/0.115/tutorial/security/simple-oauth2/
PREV
1
NEXT