This commit is contained in:
2026-11-08 20:08:53 +08:00
parent 7526a5fe4d
commit 9b924747c5
2692 changed files with 394867 additions and 0 deletions

25
ai_mcp/models/ir_http.py Normal file
View File

@@ -0,0 +1,25 @@
from werkzeug.datastructures import WWWAuthenticate
from werkzeug.exceptions import Unauthorized
from odoo import models
from odoo.http import request
from odoo.addons.ai_mcp.utils.oauth_utils import protected_resource_metadata_url
class IrHttp(models.AbstractModel):
_inherit = 'ir.http'
@classmethod
def _auth_method_bearer(cls, routing):
try:
super()._auth_method_bearer(routing)
except Unauthorized as error:
if not routing.get("bearer_scope") == "mcp":
raise
params = {"resource_metadata": protected_resource_metadata_url(request.env)}
if request.httprequest.headers.get("Authorization", "").lower().startswith("bearer "):
params["error"] = "invalid_token"
raise Unauthorized(www_authenticate=WWWAuthenticate('Bearer', params)) from error