Skip to content

Commit

Permalink
Automated deployment: Fri Jul 12 12:42:16 UTC 2024 b81d463
Browse files Browse the repository at this point in the history
  • Loading branch information
frankie567 committed Jul 12, 2024
1 parent 0c55a19 commit bb8c0cb
Show file tree
Hide file tree
Showing 10 changed files with 1,183 additions and 72 deletions.
21 changes: 21 additions & 0 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,27 @@



<li class="md-nav__item">
<a href="/reference/httpx_oauth.integrations.fastapi/" class="md-nav__link">


<span class="md-ellipsis">
httpx_oauth.integrations.fastapi
</span>


</a>
</li>










<li class="md-nav__item">
<a href="/reference/httpx_oauth.exceptions/" class="md-nav__link">

Expand Down
81 changes: 69 additions & 12 deletions fastapi/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,21 @@
</span>
</a>

<nav class="md-nav" aria-label="OAuth2AuthorizeCallback">
<ul class="md-nav__list">

<li class="md-nav__item">
<a href="#custom-exception-handler" class="md-nav__link">
<span class="md-ellipsis">
Custom exception handler
</span>
</a>

</li>

</ul>
</nav>

</li>

</ul>
Expand Down Expand Up @@ -497,6 +512,27 @@



<li class="md-nav__item">
<a href="../reference/httpx_oauth.integrations.fastapi/" class="md-nav__link">


<span class="md-ellipsis">
httpx_oauth.integrations.fastapi
</span>


</a>
</li>










<li class="md-nav__item">
<a href="../reference/httpx_oauth.exceptions/" class="md-nav__link">

Expand Down Expand Up @@ -552,6 +588,21 @@
</span>
</a>

<nav class="md-nav" aria-label="OAuth2AuthorizeCallback">
<ul class="md-nav__list">

<li class="md-nav__item">
<a href="#custom-exception-handler" class="md-nav__link">
<span class="md-ellipsis">
Custom exception handler
</span>
</a>

</li>

</ul>
</nav>

</li>

</ul>
Expand All @@ -573,18 +624,6 @@ <h1 id="fastapi">FastAPI<a class="headerlink" href="#fastapi" title="Permanent l
<p>Utilities are provided to ease the integration of an OAuth2 process in <a href="https://fastapi.tiangolo.com/">FastAPI</a>.</p>
<h2 id="oauth2authorizecallback"><code>OAuth2AuthorizeCallback</code><a class="headerlink" href="#oauth2authorizecallback" title="Permanent link">&para;</a></h2>
<p>Dependency callable to handle the authorization callback. It reads the query parameters and returns the access token and the state.</p>
<div class="admonition abstract">
<p class="admonition-title">Parameters</p>
<ul>
<li><code>client: OAuth2</code>: The OAuth2 client.</li>
<li><code>route_name: Optional[str]</code>: Name of the callback route, as defined in the <code>name</code> parameter of the route decorator.</li>
<li><code>redirect_url: Optional[str]</code>: Full URL to the callback route.</li>
</ul>
</div>
<div class="admonition tip">
<p class="admonition-title">Tip</p>
<p>You should either set <code>route_name</code>, which will automatically reverse the URL, or <code>redirect_url</code>, which is an arbitrary URL you set.</p>
</div>
<div class="highlight"><pre><span></span><code><a id="__codelineno-0-1" name="__codelineno-0-1" href="#__codelineno-0-1"></a><span class="kn">from</span> <span class="nn">fastapi</span> <span class="kn">import</span> <span class="n">FastAPI</span><span class="p">,</span> <span class="n">Depends</span>
<a id="__codelineno-0-2" name="__codelineno-0-2" href="#__codelineno-0-2"></a><span class="kn">from</span> <span class="nn">httpx_oauth.integrations.fastapi</span> <span class="kn">import</span> <span class="n">OAuth2AuthorizeCallback</span>
<a id="__codelineno-0-3" name="__codelineno-0-3" href="#__codelineno-0-3"></a><span class="kn">from</span> <span class="nn">httpx_oauth.oauth2</span> <span class="kn">import</span> <span class="n">OAuth2</span>
Expand All @@ -598,6 +637,24 @@ <h2 id="oauth2authorizecallback"><code>OAuth2AuthorizeCallback</code><a class="h
<a id="__codelineno-0-11" name="__codelineno-0-11" href="#__codelineno-0-11"></a> <span class="n">token</span><span class="p">,</span> <span class="n">state</span> <span class="o">=</span> <span class="n">access_token_state</span>
<a id="__codelineno-0-12" name="__codelineno-0-12" href="#__codelineno-0-12"></a> <span class="c1"># Do something useful</span>
</code></pre></div>
<p class="buttons"><a class="md-button" href="../reference/httpx_oauth.integrations.fastapi/">Reference</a></p>
<h3 id="custom-exception-handler">Custom exception handler<a class="headerlink" href="#custom-exception-handler" title="Permanent link">&para;</a></h3>
<p>If an error occurs inside the callback logic (the user denied access, the authorization code is invalid...), the dependency will raise <a class="autorefs autorefs-internal" href="../reference/httpx_oauth.integrations.fastapi/#httpx_oauth.integrations.fastapi.OAuth2AuthorizeCallbackError">OAuth2AuthorizeCallbackError</a>.</p>
<p>It inherits from FastAPI's <a class="autorefs autorefs-external" href="https://fastapi.tiangolo.com/reference/exceptions/#fastapi.HTTPException">HTTPException</a>, so it's automatically handled by the default FastAPI exception handler. You can customize this behavior by implementing your own exception handler for <code>OAuth2AuthorizeCallbackError</code>.</p>
<div class="highlight"><pre><span></span><code><a id="__codelineno-1-1" name="__codelineno-1-1" href="#__codelineno-1-1"></a><span class="kn">from</span> <span class="nn">fastapi</span> <span class="kn">import</span> <span class="n">FastAPI</span>
<a id="__codelineno-1-2" name="__codelineno-1-2" href="#__codelineno-1-2"></a><span class="kn">from</span> <span class="nn">httpx_oauth.integrations.fastapi</span> <span class="kn">import</span> <span class="n">OAuth2AuthorizeCallbackError</span>
<a id="__codelineno-1-3" name="__codelineno-1-3" href="#__codelineno-1-3"></a>
<a id="__codelineno-1-4" name="__codelineno-1-4" href="#__codelineno-1-4"></a><span class="n">app</span> <span class="o">=</span> <span class="n">FastAPI</span><span class="p">()</span>
<a id="__codelineno-1-5" name="__codelineno-1-5" href="#__codelineno-1-5"></a>
<a id="__codelineno-1-6" name="__codelineno-1-6" href="#__codelineno-1-6"></a><span class="nd">@app</span><span class="o">.</span><span class="n">exception_handler</span><span class="p">(</span><span class="n">OAuth2AuthorizeCallbackError</span><span class="p">)</span>
<a id="__codelineno-1-7" name="__codelineno-1-7" href="#__codelineno-1-7"></a><span class="k">async</span> <span class="k">def</span> <span class="nf">oauth2_authorize_callback_error_handler</span><span class="p">(</span><span class="n">request</span><span class="p">:</span> <span class="n">Request</span><span class="p">,</span> <span class="n">exc</span><span class="p">:</span> <span class="n">OAuth2AuthorizeCallbackError</span><span class="p">):</span>
<a id="__codelineno-1-8" name="__codelineno-1-8" href="#__codelineno-1-8"></a> <span class="n">detail</span> <span class="o">=</span> <span class="n">exc</span><span class="o">.</span><span class="n">detail</span>
<a id="__codelineno-1-9" name="__codelineno-1-9" href="#__codelineno-1-9"></a> <span class="n">status_code</span> <span class="o">=</span> <span class="n">exc</span><span class="o">.</span><span class="n">status_code</span>
<a id="__codelineno-1-10" name="__codelineno-1-10" href="#__codelineno-1-10"></a> <span class="k">return</span> <span class="n">JSONResponse</span><span class="p">(</span>
<a id="__codelineno-1-11" name="__codelineno-1-11" href="#__codelineno-1-11"></a> <span class="n">status_code</span><span class="o">=</span><span class="n">status_code</span><span class="p">,</span>
<a id="__codelineno-1-12" name="__codelineno-1-12" href="#__codelineno-1-12"></a> <span class="n">content</span><span class="o">=</span><span class="p">{</span><span class="s2">&quot;message&quot;</span><span class="p">:</span> <span class="s2">&quot;The OAuth2 callback failed&quot;</span><span class="p">,</span> <span class="s2">&quot;detail&quot;</span><span class="p">:</span> <span class="n">detail</span><span class="p">},</span>
<a id="__codelineno-1-13" name="__codelineno-1-13" href="#__codelineno-1-13"></a> <span class="p">)</span>
</code></pre></div>



Expand Down
23 changes: 22 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,27 @@



<li class="md-nav__item">
<a href="reference/httpx_oauth.integrations.fastapi/" class="md-nav__link">


<span class="md-ellipsis">
httpx_oauth.integrations.fastapi
</span>


</a>
</li>










<li class="md-nav__item">
<a href="reference/httpx_oauth.exceptions/" class="md-nav__link">

Expand Down Expand Up @@ -712,7 +733,7 @@ <h1 id="httpx-oauth">HTTPX OAuth<a class="headerlink" href="#httpx-oauth" title=
<a href="https://codecov.io/gh/frankie567/httpx-oauth"><img alt="codecov" src="https://codecov.io/gh/frankie567/httpx-oauth/branch/master/graph/badge.svg" /></a>
<a href="https://badge.fury.io/py/httpx-oauth"><img alt="PyPI version" src="https://badge.fury.io/py/httpx-oauth.svg" /></a></p>
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
<p><a href="#contributors-"><img alt="All Contributors" src="https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square" /></a></p>
<p><a href="#contributors"><img alt="All Contributors" src="https://img.shields.io/badge/all_contributors-14-orange.svg?style=flat-square" /></a></p>
<!-- ALL-CONTRIBUTORS-BADGE:END -->

<p align="center">
Expand Down
Binary file modified objects.inv
Binary file not shown.
Loading

0 comments on commit bb8c0cb

Please sign in to comment.