ir_http.py
854 Bytes
# https://github.com/OCA/server-auth/blob/16.0/auth_api_key/models/ir_http.py
# https://gitlab.com/hazem.abdalazeem/project_api/-/blob/main/controllers/login.py
import logging
from odoo import models
from odoo.exceptions import AccessDenied
from odoo.http import request
_logger = logging.getLogger(__name__)
class IrHttp(models.AbstractModel):
_inherit = 'ir.http'
@classmethod
def _auth_method_api_key(cls):
headers = request.httprequest.environ
api_key = headers.get('HTTP_API_KEY')
if api_key:
uid = request.env['res.users.apikeys']._check_credentials(
scope='rpc', key=api_key)
if not uid:
raise AccessDenied()
request.update_env(user=uid)
return True
_logger.error('Butuh header API-KEY')
raise AccessDenied()