Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
exclude: |
(?x)
# NOT INSTALLABLE ADDONS
^extendable/|
^fastapi_auth_jwt_demo/|
# END NOT INSTALLABLE ADDONS
# Files and folders generated by bots, to avoid loops
^setup/|/static/description/index\.html$|
Expand Down
6 changes: 1 addition & 5 deletions base_rest/README.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
.. image:: https://odoo-community.org/readme-banner-image
:target: https://odoo-community.org/get-involved?utm_source=readme
:alt: Odoo Community Association

=========
Base Rest
=========
Expand All @@ -17,7 +13,7 @@ Base Rest
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/license-LGPL--3-blue.png
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
Expand Down
3 changes: 1 addition & 2 deletions base_rest/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"assets": {
"web.assets_frontend": [
"base_rest/static/src/scss/base_rest.scss",
"base_rest/static/src/js/swagger_ui.js",
"base_rest/static/src/js/swagger.js",
"base_rest/static/src/js/components/swagger_ui.esm.js",
],
},
"external_dependencies": {
Expand Down
100 changes: 47 additions & 53 deletions base_rest/static/description/index.html

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ class SwaggerUI extends Component {
}

(function () {
// eslint-disable-next-line
"use strict";

whenReady(() => {
Expand Down
2 changes: 1 addition & 1 deletion base_rest/views/openapi_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@

<script
type="text/javascript"
src="/base_rest/static/src/js/components/swagger_ui.js"
src="/base_rest/static/src/js/components/swagger_ui.esm.js"
/>
</t>
<t t-set="head" t-value="head" />
Expand Down
2 changes: 1 addition & 1 deletion base_rest_auth_api_key/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ <h1>Base Rest Auth Api Key</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7c57ea5f8972ccd3fd126f96da0ff252203ec8d51cb0a1f2e4a1b101e730d838
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/license-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/18.0/base_rest_auth_api_key"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-base_rest_auth_api_key"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/rest-framework/tree/18.0/base_rest_auth_api_key"><img alt="OCA/rest-framework" src="https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-base_rest_auth_api_key"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This technical addon extend base_rest to add the support for
auth_api_key authentication mechanism into the generated openapi
documentation.</p>
Expand Down
1 change: 0 additions & 1 deletion extendable/tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from contextlib import contextmanager

import odoo
from odoo import SUPERUSER_ID, api
from odoo.modules.registry import Registry
from odoo.tests import common
Expand Down
87 changes: 87 additions & 0 deletions fastapi_auth_jwt_demo/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
=====================
FastAPI Auth JWT Test
=====================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:7e014d71c6caa0eee959cdf9b1153e4ef259b88623dbdac5ff634a95ccfd0695
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Frest--framework-lightgray.png?logo=github
:target: https://github.com/OCA/rest-framework/tree/18.0/fastapi_auth_jwt_demo
:alt: OCA/rest-framework
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/rest-framework-18-0/rest-framework-18-0-fastapi_auth_jwt_demo
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/rest-framework&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Tests and demo routes for ``fastapi_auth_jwt``.

The tests and routes are almost identical to those in ``auth_jwt_demo``,
and the JWT validators used are those from ``auth_jwt_demo``.

**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/rest-framework/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/rest-framework/issues/new?body=module:%20fastapi_auth_jwt_demo%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* ACSONE SA/NV

Contributors
------------

Mohamed Alkobrosli <[email protected]>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

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.

.. |maintainer-sbidoul| image:: https://github.com/sbidoul.png?size=40px
:target: https://github.com/sbidoul
:alt: sbidoul

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-sbidoul|

This module is part of the `OCA/rest-framework <https://github.com/OCA/rest-framework/tree/18.0/fastapi_auth_jwt_demo>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions fastapi_auth_jwt_demo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import routers
17 changes: 17 additions & 0 deletions fastapi_auth_jwt_demo/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2023 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "FastAPI Auth JWT Test",
"summary": """
Test/demo module for fastapi_auth_jwt.""",
"version": "18.0.0.0.0",
"license": "LGPL-3",
"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": [],
"demo": ["demo/fastapi_endpoint.xml"],
"installable": True,
}
9 changes: 9 additions & 0 deletions fastapi_auth_jwt_demo/demo/fastapi_endpoint.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record model="fastapi.endpoint" id="fastapi_endpoint_auth_jwt_demo">
<field name="name">Auth JWT Fastapi Demo Endpoint</field>
<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" />
</record>
</odoo>
29 changes: 29 additions & 0 deletions fastapi_auth_jwt_demo/i18n/fastapi_auth_jwt_demo.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * fastapi_auth_jwt_demo
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: fastapi_auth_jwt_demo
#: model:ir.model.fields,field_description:fastapi_auth_jwt_demo.field_fastapi_endpoint__app
msgid "App"
msgstr ""

#. module: fastapi_auth_jwt_demo
#: model:ir.model.fields.selection,name:fastapi_auth_jwt_demo.selection__fastapi_endpoint__app__auth_jwt_demo
msgid "Auth JWT Demo Endpoint"
msgstr ""

#. module: fastapi_auth_jwt_demo
#: model:ir.model,name:fastapi_auth_jwt_demo.model_fastapi_endpoint
msgid "FastAPI Endpoint"
msgstr ""
1 change: 1 addition & 0 deletions fastapi_auth_jwt_demo/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .fastapi_endpoint import FastapiEndpoint, auth_jwt_demo_api_router
23 changes: 23 additions & 0 deletions fastapi_auth_jwt_demo/models/fastapi_endpoint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2023 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo import api, fields, models

from ..routers.auth_jwt_demo_api import router as auth_jwt_demo_api_router

APP_NAME = "auth_jwt_demo"


class FastapiEndpoint(models.Model):
_inherit = "fastapi.endpoint"

app: str = fields.Selection(
selection_add=[(APP_NAME, "Auth JWT Demo Endpoint")],
ondelete={APP_NAME: "cascade"},
)

@api.model
def _get_fastapi_routers(self):
if self.app == APP_NAME:
return [auth_jwt_demo_api_router]
return super()._get_fastapi_routers()
3 changes: 3 additions & 0 deletions fastapi_auth_jwt_demo/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions fastapi_auth_jwt_demo/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Mohamed Alkobrosli \<<[email protected]>\>
4 changes: 4 additions & 0 deletions fastapi_auth_jwt_demo/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Tests and demo routes for `fastapi_auth_jwt`.

The tests and routes are almost identical to those in `auth_jwt_demo`,
and the JWT validators used are those from `auth_jwt_demo`.
1 change: 1 addition & 0 deletions fastapi_auth_jwt_demo/routers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .auth_jwt_demo_api import router
113 changes: 113 additions & 0 deletions fastapi_auth_jwt_demo/routers/auth_jwt_demo_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Copyright 2023 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from typing import Annotated

from pydantic import BaseModel

from odoo.addons.base.models.res_partner import Partner
from odoo.addons.fastapi_auth_jwt.dependencies import AuthJwtPartner

from fastapi import APIRouter, Depends


class TestData(BaseModel):
name: str | None = None
email: str | None = None
uid: int


router = APIRouter()


@router.get("/whoami", response_model=TestData)
def whoami(
partner: Annotated[
Partner,
Depends(AuthJwtPartner(validator_name="demo")),
],
) -> TestData:
return TestData(
name=partner.name,
email=partner.email,
uid=partner.env.uid,
)


@router.get("/whoami-public-or-jwt", response_model=TestData)
def whoami_public_or_jwt(
partner: Annotated[
Partner,
Depends(AuthJwtPartner(validator_name="demo", allow_unauthenticated=True)),
],
):
if partner:
return TestData(
name=partner.name,
email=partner.email,
uid=partner.env.uid,
)
return TestData(uid=partner.env.uid)


@router.get("/cookie/whoami", response_model=TestData)
def whoami_cookie(
partner: Annotated[
Partner,
Depends(AuthJwtPartner(validator_name="demo_cookie")),
],
):
return TestData(
name=partner.name,
email=partner.email,
uid=partner.env.uid,
)


@router.get("/cookie/whoami-public-or-jwt", response_model=TestData)
def whoami_cookie_public_or_jwt(
partner: Annotated[
Partner,
Depends(
AuthJwtPartner(validator_name="demo_cookie", allow_unauthenticated=True)
),
],
):
if partner:
return TestData(
name=partner.name,
email=partner.email,
uid=partner.env.uid,
)
return TestData(uid=partner.env.uid)


@router.get("/keycloak/whoami", response_model=TestData)
def whoami_keycloak(
partner: Annotated[
Partner, Depends(AuthJwtPartner(validator_name="demo_keycloak"))
],
):
return TestData(
name=partner.name,
email=partner.email,
uid=partner.env.uid,
)


@router.get("/keycloak/whoami-public-or-jwt", response_model=TestData)
def whoami_keycloak_public_or_jwt(
partner: Annotated[
Partner,
Depends(
AuthJwtPartner(validator_name="demo_keycloak", allow_unauthenticated=True)
),
],
):
if partner:
return TestData(
name=partner.name,
email=partner.email,
uid=partner.env.uid,
)
return TestData(uid=partner.env.uid)
Binary file added fastapi_auth_jwt_demo/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading