Skip to content

Commit

Permalink
[FIX] fastapi_auth_jwt_demo: assign and show Auth Jwt Validator
Browse files Browse the repository at this point in the history
  • Loading branch information
kobros-tech committed Nov 8, 2024
1 parent c89c938 commit 458aec1
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 10 deletions.
5 changes: 5 additions & 0 deletions fastapi_auth_jwt_demo/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ Authors

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~

Mohamed Alkobrosli <alkobroslymohamed@gmail.com>

Maintainers
~~~~~~~~~~~

Expand Down
6 changes: 4 additions & 2 deletions fastapi_auth_jwt_demo/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"maintainers": ["sbidoul"],
"website": "https://github.com/OCA/rest-framework",
"depends": ["fastapi_auth_jwt", "auth_jwt_demo"],
"data": [],
"depends": ["fastapi", "fastapi_auth_jwt", "auth_jwt_demo"],
"data": [
"views/fastapi_endpoint_demo.xml",
],
"demo": ["demo/fastapi_endpoint.xml"],
}
1 change: 1 addition & 0 deletions fastapi_auth_jwt_demo/demo/fastapi_endpoint.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
<field name="app">auth_jwt_demo</field>
<field name="root_path">/fastapi_auth_jwt_demo</field>
<field name="user_id" ref="fastapi.my_demo_app_user" />
<field name="auth_jwt_validator_id" ref="auth_jwt_demo.demo_validator" />
</record>
</odoo>
1 change: 1 addition & 0 deletions fastapi_auth_jwt_demo/models/fastapi_endpoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FastapiEndpoint(models.Model):
selection_add=[(APP_NAME, "Auth JWT Demo Endpoint")],
ondelete={APP_NAME: "cascade"},
)
auth_jwt_validator_id = fields.Many2one("auth.jwt.validator")

@api.model
def _get_fastapi_routers(self):
Expand Down
1 change: 1 addition & 0 deletions fastapi_auth_jwt_demo/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mohamed Alkobrosli <alkobroslymohamed@gmail.com>
21 changes: 14 additions & 7 deletions fastapi_auth_jwt_demo/static/description/index.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
Expand All @@ -9,10 +8,11 @@

/*
:Author: David Goodger (goodger@python.org)
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
:Copyright: This stylesheet has been placed in the public domain.
Default cascading style sheet for the HTML output of Docutils.
Despite the name, some widely supported CSS2 features are used.
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
customize this style sheet.
Expand Down Expand Up @@ -275,7 +275,7 @@
margin-left: 2em ;
margin-right: 2em }

pre.code .ln { color: grey; } /* line numbers */
pre.code .ln { color: gray; } /* line numbers */
pre.code, code { background-color: #eeeeee }
pre.code .comment, code .comment { color: #5C6576 }
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
Expand All @@ -301,7 +301,7 @@
span.pre {
white-space: pre }

span.problematic {
span.problematic, pre.problematic {
color: red }

span.section-subtitle {
Expand Down Expand Up @@ -379,7 +379,8 @@ <h1 class="title">FastAPI Auth JWT Test</h1>
<li><a class="reference internal" href="#bug-tracker" id="toc-entry-1">Bug Tracker</a></li>
<li><a class="reference internal" href="#credits" id="toc-entry-2">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-3">Authors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-4">Maintainers</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-4">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-5">Maintainers</a></li>
</ul>
</li>
</ul>
Expand All @@ -400,10 +401,16 @@ <h2><a class="toc-backref" href="#toc-entry-3">Authors</a></h2>
<li>ACSONE SA/NV</li>
</ul>
</div>
<div class="section" id="contributors">
<h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
<p>Mohamed Alkobrosli &lt;<a class="reference external" href="mailto:alkobroslymohamed&#64;gmail.com">alkobroslymohamed&#64;gmail.com</a>&gt;</p>
</div>
<div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-4">Maintainers</a></h2>
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
<a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
</a>
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.</p>
Expand Down
2 changes: 1 addition & 1 deletion fastapi_auth_jwt_demo/tests/test_fastapi_auth_jwt_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def test_whoami_cookie(self):

def test_forbidden(self):
"""A end-to-end test with negative authentication."""
token = self._get_token(aud="invalid")
token = self._get_token(email="invalid@example.com")
resp = self.url_open(
"/fastapi_auth_jwt_demo/whoami", headers={"Authorization": token}
)
Expand Down
26 changes: 26 additions & 0 deletions fastapi_auth_jwt_demo/views/fastapi_endpoint_demo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2022 ACSONE SA/NV
License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL). -->
<odoo>

<record model="ir.ui.view" id="fastapi_endpoint_demo_jwt_form_view">
<field name="name">fastapi.endpoint.demo.jwt.form</field>
<field name="model">fastapi.endpoint</field>
<field name="inherit_id" ref="fastapi.fastapi_endpoint_form_view" />
<field name="arch" type="xml">
<span name="configuration" position="after">
<group
name="jwt_demo_app_configuration"
title="Configuration"
attrs="{'invisible': [('app', '!=', 'auth_jwt_demo')]}"
>
<field
name="auth_jwt_validator_id"
attrs="{'required': [('app', '=', 'auth_jwt_demo')]}"
/>
</group>
</span>
</field>
</record>

</odoo>

0 comments on commit 458aec1

Please sign in to comment.