Results of 1 - 10 of about 16 for Token (0.010 sec.)
- OAuth2 scopes 10917
- 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
...ts that change from the examples in the main Tutorial - User Guide for OAuth2 with Password (and hashing), Bearer with JWT tokens . Now using OAuth2 scopes: Python 3.10+ from datetime import datetime , timedelta , timezone from typing import Annotated....security import ( OAuth2PasswordBearer , OAuth2PasswordRequestForm , SecurityScopes , ) from jwt.exceptions import InvalidTokenError from passlib.context import CryptContext from pydantic import BaseModel , ValidationError # to get a string like this...sl rand -hex 32 SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7" ALGORITHM = "HS256" ACCESS_TOKEN_EXPIRE_MINUTES = 30 fake_users_db = { "johndoe" : { "username" : "johndoe" , "full_name" : "John Doe" , "email" : "johndoe... - https://man.mtool.work/fastapi/0.115/advanced/security/oauth2-scopes/
- パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer 10587
- パスワード(およびハッシュ化)によるOAuth2、JWTトークンによるBearer これでセキュリティの流れが全てわかったので、 JWT トークンと安全なパスワードのハッシュ化を使用して、実際にアプリケーションを安全にしてみましょう。 このコードは、アプリケーシ
...いった用途に利用できます。 本章では、前章の続きから始めて、コードをアップデートしていきます。 JWT について JWTとは「JSON Web Tokens」の略称です。 JSONオブジェクトをスペースのない長く密集した文字列で表現したトークンの仕様です。例えば次のようになります: e...n , status from fastapi.security import OAuth2PasswordBearer , OAuth2PasswordRequestForm from jwt.exceptions import InvalidTokenError from passlib.context import CryptContext from pydantic import BaseModel # to get a string like this run: # openssl ra...nd -hex 32 SECRET_KEY = "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7" ALGORITHM = "HS256" ACCESS_TOKEN_EXPIRE_MINUTES = 30 fake_users_db = { "johndoe" : { "username" : "johndoe" , "full_name" : "John Doe" , "email" : "johndoe... - https://man.mtool.work/fastapi/0.115/tutorial/security/oauth2-jwt/
- 現在のユーザーの取得 10397
- 現在のユーザーの取得 一つ前の章では、(依存性注入システムに基づいた)セキュリティシステムは、 path operation関数 に str として token を与えていました: Python 3.8+ - non-Annotated from fastapi import Depends , FastAPI from fastapi.security i
...mport OAuth2PasswordBearer app = FastAPI () oauth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" ) @app . get ( "/items/" ) async def read_items ( token : str = Depends ( oauth2_scheme )): return { "token"...: token } ? Other versions and variants Python 3.9+ Python 3.8+ from typing import Annotated from fastapi import Depends , FastAPI...from fastapi.security import OAuth2PasswordBearer app = FastAPI () oauth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" ) @app . get ( "/items/" ) async def read_items ( token : Annotated [ str , Depends ( oauth2_scheme )]): retu... - https://man.mtool.work/fastapi/0.115/tutorial/security/get-current-user/
- Simple OAuth2 with Password and Bearer 10275
- 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
...rdRequestForm First, import OAuth2PasswordRequestForm , and use it as a dependency with Depends in the path operation for /token : Python 3.10+ from typing import Annotated from fastapi import Depends , FastAPI , HTTPException , status from fastapi.se...astAPI () def fake_hash_password ( password : str ): return "fakehashed" + password oauth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" ) class User ( BaseModel ): username : str email : str | None = None full_name : str | None = None disabled :...( db , username : str ): if username in db : user_dict = db [ username ] return UserInDB ( ** user_dict ) def fake_decode_token ( token ): # This doesn't provide any security at all # Check the next version user = get_user ( fake_users_db , token ) r... - https://man.mtool.work/fastapi/0.115/tutorial/security/simple-oauth2/
- path operationデコレータの依存関係 9825
- path operationデコレータの依存関係 場合によっては path operation関数 の中で依存関係の戻り値を本当に必要としないこともあります。 もしくは、依存関係が値を返さない場合もあります。 しかし、それでも実行・解決する必要があります。 このような場合、
...thon 3.8+ - non-Annotated from fastapi import Depends , FastAPI , 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 HTTPExcepti...tus_code = 400 , detail = "X-Key header invalid" ) return x_key @app . get ( "/items/" , dependencies = [ Depends ( verify_token ), Depends ( verify_key )]) async def read_items (): return [{ "item" : "Foo" }, { "item" : "Bar" }] ? Other versions and... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/dependencies-in-path-...
- テスト 9721
- テスト Starlette のおかげで、 FastAPI アプリケーションのテストは簡単で楽しいものになっています。 HTTPX がベースなので、非常に使いやすく直感的です。 これを使用すると、 FastAPI と共に pytest を直接利用できます。 TestClient を使用 TestClient を
...ーションがあります。 また、いくつかのエラーを返す可能性のある POST オペレーションもあります。 これらの path operation には X-Token ヘッダーが必要です。 Python 3.10+ - non-Annotated from fastapi import FastAPI , Header , HTTPException from pydantic impor...t BaseModel fake_secret_token = "coneofsilence" fake_db = { "foo" : { "id" : "foo" , "title" : "Foo" , "description" : "There goes my hero" }, "bar" : {...on : str | None = None @app . get ( "/items/ {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... - https://man.mtool.work/fastapi/0.115/tutorial/testing/
- WebSocket 9288
- WebSocket FastAPI で WebSocket が使用できます。 WebSockets のインストール まず WebSockets のインストールが必要です。 $ pip install websockets ---> 100% WebSocket クライアント 本番環境 本番環境では、React、Vue.js、Angularなどの最新のフレーム
...ubmit="sendMessage(event)"> <label>Item ID: <input type="text" id="itemId" autocomplete="off" value="foo"/></label> <label>Token: <input type="text" id="token" autocomplete="off" value="some-key-token"/></label> <button onclick="connect(event)">Connec...id='messages'> </ul> <script> var ws = null; function connect(event) { var itemId = document.getElementById("itemId") var token = document.getElementById("token") ws = new WebSocket("ws://localhost:8000/items/" + itemId.value + "/ws?token=" + token.v...} </script> </body> </html> """ @app . get ( "/" ) async def get (): return HTMLResponse ( html ) async def get_cookie_or_token ( websocket : WebSocket , session : Union [ str , None ] = Cookie ( default = None ), token : Union [ str , None ] = Query... - https://man.mtool.work/fastapi/0.115/advanced/websockets/
- Bigger Applications - Multiple Files 9184
- 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
...put them in their own dependencies module ( app/dependencies.py ). We will now use a simple dependency to read a custom X-Token header: Python 3.9+ Python 3.8+ Python 3.8+ non-Annotated app/dependencies.py from typing import Annotated from fastapi im...port Header , HTTPException async def get_token_header ( x_token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_c...ode = 400 , detail = "X-Token header invalid" ) async def get_query_token ( token : str ): if token != "jessica" : raise HTTPException ( status_code = 4... - https://man.mtool.work/fastapi/0.115/tutorial/bigger-applications/
- セキュリティ - 最初の一歩 8976
- セキュリティ - 最初の一歩 あるドメインに、 バックエンド APIを持っているとしましょう。 そして、別のドメインか同じドメインの違うパス(またはモバイルアプリケーションの中)に フロントエンド を持っています。 さらに、フロントエンドが ユーザー名 と
...epends , FastAPI from fastapi.security import OAuth2PasswordBearer app = FastAPI () oauth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" ) @app . get ( "/items/" ) async def read_items ( token : str = Depends ( oauth2_scheme )): return { "token"...: token } ? Other versions and variants Python 3.9+ Python 3.8+ from typing import Annotated from fastapi import Depends , FastAPI...from fastapi.security import OAuth2PasswordBearer app = FastAPI () oauth2_scheme = OAuth2PasswordBearer ( tokenUrl = "token" ) @app . get ( "/items/" ) async def read_items ( token : Annotated [ str , Depends ( oauth2_scheme )]): retu... - https://man.mtool.work/fastapi/0.115/tutorial/security/first-steps/
- Global Dependencies 8768
- 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
...9+ from fastapi import Depends , FastAPI , Header , HTTPException from typing_extensions import Annotated async def verify_token ( x_token : Annotated [ str , Header ()]): if x_token != "fake-super-secret-token" : raise HTTPException ( status_code = 4...00 , detail = "X-Token header invalid" ) async def verify_key ( x_key : Annotated [ str , Header ()]): if x_key != "fake-super-secret-key" : rais...ion ( status_code = 400 , detail = "X-Key header invalid" ) return x_key app = FastAPI ( dependencies = [ Depends ( verify_token ), Depends ( verify_key )]) @app . get ( "/items/" ) async def read_items (): return [{ "item" : "Portal Gun" }, { "item"... - https://man.mtool.work/fastapi/0.115/tutorial/dependencies/global-dependencies/