<p dir="auto">Strict mypy mode gives such errors:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="base/api/users/controllers.py:4: error: Module 'fastapi' has no attribute 'Depends'
base/api/users/controllers.py:4: error: Module 'fastapi' has no attribute 'HTTPException'"><pre class="notranslate"><code class="notranslate">base/api/users/controllers.py:4: error: Module 'fastapi' has no attribute 'Depends'
base/api/users/controllers.py:4: error: Module 'fastapi' has no attribute 'HTTPException'
</code></pre></div>
<p dir="auto">on such import statement:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from fastapi import Depends, HTTPException"><pre class="notranslate"><code class="notranslate">from fastapi import Depends, HTTPException
</code></pre></div>
<p dir="auto">Tried using</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="from fastapi import Depends as Depends
from fastapi import HTTPException as HTTPException"><pre class="notranslate"><code class="notranslate">from fastapi import Depends as Depends
from fastapi import HTTPException as HTTPException
</code></pre></div>
<p dir="auto">as per recommendations in <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="628610814" data-permission-text="Title is private" data-url="https://github.com/tiangolo/typer/issues/112" data-hovercard-type="issue" data-hovercard-url="/tiangolo/typer/issues/112/hovercard" href="https://github.com/tiangolo/typer/issues/112">tiangolo/typer#112</a> discussion. But the errors remain.</p>
<p dir="auto">It seems that adding <strong>all</strong> to the <strong>init</strong>.py files for the stuff that's reexported is a way to go (as per <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="459406387" data-permission-text="Title is private" data-url="https://github.com/python/mypy/issues/7042" data-hovercard-type="issue" data-hovercard-url="/python/mypy/issues/7042/hovercard" href="https://github.com/python/mypy/issues/7042">python/mypy#7042</a> discussion).</p>
<p dir="auto">Thanks for considering this!</p>
<h3 dir="auto">Description</h3>
<p dir="auto">I want to use the jwt auth, and learn the tutorial about it. There are sth confused me:</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="@router.post('/token')
async def login(form_data: OAuth2PasswordRequestForm = Depends()):
    user = await authenticate_user(form_data.username, form_data.password)
    if not user:
        raise HTTPException(status_code=400, detail='incorrect username')
    access_token_expires = timedelta(minutes=ACCESS_TOKEN_EXPIRE_MINUTES)
    access_token = await create_access_token(data={'sub': user.username}, expires_delta=access_token_expires)
    return {'access_token': access_token, 'token_type': 'bearer'}"><pre class="notranslate"><span class="pl-en">@<span class="pl-s1">router</span>.<span class="pl-en">post</span>(<span class="pl-s">'/token'</span>)</span>
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">login</span>(<span class="pl-s1">form_data</span>: <span class="pl-v">OAuth2PasswordRequestForm</span> <span class="pl-c1">=</span> <span class="pl-v">Depends</span>()):
    <span class="pl-s1">user</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-en">authenticate_user</span>(<span class="pl-s1">form_data</span>.<span class="pl-s1">username</span>, <span class="pl-s1">form_data</span>.<span class="pl-s1">password</span>)
    <span class="pl-k">if</span> <span class="pl-c1">not</span> <span class="pl-s1">user</span>:
        <span class="pl-k">raise</span> <span class="pl-v">HTTPException</span>(<span class="pl-s1">status_code</span><span class="pl-c1">=</span><span class="pl-c1">400</span>, <span class="pl-s1">detail</span><span class="pl-c1">=</span><span class="pl-s">'incorrect username'</span>)
    <span class="pl-s1">access_token_expires</span> <span class="pl-c1">=</span> <span class="pl-en">timedelta</span>(<span class="pl-s1">minutes</span><span class="pl-c1">=</span><span class="pl-v">ACCESS_TOKEN_EXPIRE_MINUTES</span>)
    <span class="pl-s1">access_token</span> <span class="pl-c1">=</span> <span class="pl-k">await</span> <span class="pl-en">create_access_token</span>(<span class="pl-s1">data</span><span class="pl-c1">=</span>{<span class="pl-s">'sub'</span>: <span class="pl-s1">user</span>.<span class="pl-s1">username</span>}, <span class="pl-s1">expires_delta</span><span class="pl-c1">=</span><span class="pl-s1">access_token_expires</span>)
    <span class="pl-k">return</span> {<span class="pl-s">'access_token'</span>: <span class="pl-s1">access_token</span>, <span class="pl-s">'token_type'</span>: <span class="pl-s">'bearer'</span>}</pre></div>
<p dir="auto">If login success, the token will be returned , and next time you send other request need auth like</p>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="oauth2_scheme = OAuth2PasswordBearer(tokenUrl='/token')
async def get_current_user(token: str=Depends(oauth2_scheme)):
    pass"><pre class="notranslate"><span class="pl-s1">oauth2_scheme</span> <span class="pl-c1">=</span> <span class="pl-v">OAuth2PasswordBearer</span>(<span class="pl-s1">tokenUrl</span><span class="pl-c1">=</span><span class="pl-s">'/token'</span>)
<span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">get_current_user</span>(<span class="pl-s1">token</span>: <span class="pl-s1">str</span><span class="pl-c1">=</span><span class="pl-v">Depends</span>(<span class="pl-s1">oauth2_scheme</span>)):
    <span class="pl-k">pass</span></pre></div>
<ul dir="auto">
<li>How does it works the next request was added a header with Authorization: Bear automically? Where does the token returned stored?</li>
<li>When I replace the Form with json, the following requests after login are failing to be with Auth Header</li>
</ul>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="async def login(user_data: schemas.UserLogin):
    pass"><pre class="notranslate"><span class="pl-k">async</span> <span class="pl-k">def</span> <span class="pl-en">login</span>(<span class="pl-s1">user_data</span>: <span class="pl-s1">schemas</span>.<span class="pl-v">UserLogin</span>):
    <span class="pl-k">pass</span></pre></div>
<p dir="auto">I am sorry about my English and less experience about auth in Web, wish you could solve my confusion. Thanks in advance.</p>