Skip to content

Latest commit

 

History

History
151 lines (88 loc) · 4.37 KB

get-current-user.md

File metadata and controls

151 lines (88 loc) · 4.37 KB

🤚 ⏮️ 👩‍💻

⏮️ 📃 💂‍♂ ⚙️ (❔ 🧢 🔛 🔗 💉 ⚙️) 🤝 ➡ 🛠️ 🔢 token str:

{!../../../docs_src/security/tutorial001.py!}

✋️ 👈 🚫 👈 ⚠.

➡️ ⚒ ⚫️ 🤝 👥 ⏮️ 👩‍💻.

✍ 👩‍💻 🏷

🥇, ➡️ ✍ Pydantic 👩‍💻 🏷.

🎏 🌌 👥 ⚙️ Pydantic 📣 💪, 👥 💪 ⚙️ ⚫️ 🙆 🙆:

=== "🐍 3️⃣.6️⃣ & 🔛"

```Python hl_lines="5  12-16"
{!> ../../../docs_src/security/tutorial002.py!}
```

=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"

```Python hl_lines="3  10-14"
{!> ../../../docs_src/security/tutorial002_py310.py!}
```

get_current_user 🔗

➡️ ✍ 🔗 get_current_user.

💭 👈 🔗 💪 ✔️ 🎧-🔗 ❓

get_current_user 🔜 ✔️ 🔗 ⏮️ 🎏 oauth2_scheme 👥 ✍ ⏭.

🎏 👥 🔨 ⏭ ➡ 🛠️ 🔗, 👆 🆕 🔗 get_current_user 🔜 📨 token str ⚪️➡️ 🎧-🔗 oauth2_scheme:

=== "🐍 3️⃣.6️⃣ & 🔛"

```Python hl_lines="25"
{!> ../../../docs_src/security/tutorial002.py!}
```

=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"

```Python hl_lines="23"
{!> ../../../docs_src/security/tutorial002_py310.py!}
```

🤚 👩‍💻

get_current_user 🔜 ⚙️ (❌) 🚙 🔢 👥 ✍, 👈 ✊ 🤝 str & 📨 👆 Pydantic User 🏷:

=== "🐍 3️⃣.6️⃣ & 🔛"

```Python hl_lines="19-22  26-27"
{!> ../../../docs_src/security/tutorial002.py!}
```

=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"

```Python hl_lines="17-20  24-25"
{!> ../../../docs_src/security/tutorial002_py310.py!}
```

💉 ⏮️ 👩‍💻

🔜 👥 💪 ⚙️ 🎏 Depends ⏮️ 👆 get_current_user ➡ 🛠️:

=== "🐍 3️⃣.6️⃣ & 🔛"

```Python hl_lines="31"
{!> ../../../docs_src/security/tutorial002.py!}
```

=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"

```Python hl_lines="29"
{!> ../../../docs_src/security/tutorial002_py310.py!}
```

👀 👈 👥 📣 🆎 current_user Pydantic 🏷 User.

👉 🔜 ℹ 🇺🇲 🔘 🔢 ⏮️ 🌐 🛠️ & 🆎 ✅.

!!! tip 👆 5️⃣📆 💭 👈 📨 💪 📣 ⏮️ Pydantic 🏷.

📥 **FastAPI** 🏆 🚫 🤚 😨 ↩️ 👆 ⚙️ `Depends`.

!!! check 🌌 👉 🔗 ⚙️ 🏗 ✔ 👥 ✔️ 🎏 🔗 (🎏 "☑") 👈 🌐 📨 User 🏷.

👥 🚫 🚫 ✔️ 🕴 1️⃣ 🔗 👈 💪 📨 👈 🆎 💽.

🎏 🏷

👆 💪 🔜 🤚 ⏮️ 👩‍💻 🔗 ➡ 🛠️ 🔢 & 🙅 ⏮️ 💂‍♂ 🛠️ 🔗 💉 🎚, ⚙️ Depends.

& 👆 💪 ⚙️ 🙆 🏷 ⚖️ 💽 💂‍♂ 📄 (👉 💼, Pydantic 🏷 User).

✋️ 👆 🚫 🚫 ⚙️ 🎯 💽 🏷, 🎓 ⚖️ 🆎.

👆 💚 ✔️ id & email & 🚫 ✔️ 🙆 username 👆 🏷 ❓ 💭. 👆 💪 ⚙️ 👉 🎏 🧰.

👆 💚 ✔️ str❓ ⚖️ dict❓ ⚖️ 💽 🎓 🏷 👐 🔗 ❓ ⚫️ 🌐 👷 🎏 🌌.

👆 🤙 🚫 ✔️ 👩‍💻 👈 🕹 👆 🈸 ✋️ 🤖, 🤖, ⚖️ 🎏 ⚙️, 👈 ✔️ 🔐 🤝 ❓ 🔄, ⚫️ 🌐 👷 🎏.

⚙️ 🙆 😇 🏷, 🙆 😇 🎓, 🙆 😇 💽 👈 👆 💪 👆 🈸. FastAPI ✔️ 👆 📔 ⏮️ 🔗 💉 ⚙️.

📟 📐

👉 🖼 5️⃣📆 😑 🔁. ✔️ 🤯 👈 👥 🌀 💂‍♂, 📊 🏷, 🚙 🔢 & ➡ 🛠️ 🎏 📁.

✋️ 📥 🔑 ☝.

💂‍♂ & 🔗 💉 💩 ✍ 🕐.

& 👆 💪 ⚒ ⚫️ 🏗 👆 💚. & , ✔️ ⚫️ ✍ 🕴 🕐, 👁 🥉. ⏮️ 🌐 💪.

✋️ 👆 💪 ✔️ 💯 🔗 (➡ 🛠️) ⚙️ 🎏 💂‍♂ ⚙️.

& 🌐 👫 (⚖️ 🙆 ↔ 👫 👈 👆 💚) 💪 ✊ 📈 🏤-⚙️ 👫 🔗 ⚖️ 🙆 🎏 🔗 👆 ✍.

& 🌐 👉 💯 ➡ 🛠️ 💪 🤪 3️⃣ ⏸:

=== "🐍 3️⃣.6️⃣ & 🔛"

```Python hl_lines="30-32"
{!> ../../../docs_src/security/tutorial002.py!}
```

=== "🐍 3️⃣.1️⃣0️⃣ & 🔛"

```Python hl_lines="28-30"
{!> ../../../docs_src/security/tutorial002_py310.py!}
```

🌃

👆 💪 🔜 🤚 ⏮️ 👩‍💻 🔗 👆 ➡ 🛠️ 🔢.

👥 ⏪ 😬 📤.

👥 💪 🚮 ➡ 🛠️ 👩‍💻/👩‍💻 🤙 📨 username & password.

👈 👟 ⏭.