Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

How i can auth my user to access odoo with API Key or Access Token?

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
authenticationapi
4 Replies
44109 Rodiniai
Portretas
Usman Farzand

i'm using Odoo 14 CE
using addon
https://apps.odoo.com/apps/modules/12.0/auth_api_key/
api_key = 123456789
localhost:8069/my_service?api_key=123456789

wher is my configuration went wrong ?

@http.route('/my_service', auth='api_key', type='json')
def my_service(self, *args, **kwargs):
pass    
1
Portretas
Atmesti
DevHerles
Hey @Usman, how did you do it?
Usman Farzand

you can see the answer

OdooBot
Hello,
Thank you for your email. I am currently out of the office due to illness. I am  unable to respond to messages at this time.
Thank you for your understanding. I will respond to your message as soon as I am able.
Portretas
Michael Jurke
Best Answer

If you do not like to use the addon, you can add your own auth method and use the Developer API Key of Odoo 14 (you can add API keys in the preferences now):



class IrHttp(models.AbstractModel):
_inherit = "ir.http"

@classmethod
def _auth_method_my_api_key(cls):
api_key = request.httprequest.headers.get("Authorization")
if not api_key:
raise BadRequest("Authorization header with API key missing")

user_id = request.env["res.users.apikeys"]._check_credentials(
scope="rpc", key=api_key
)
if not user_id:
raise BadRequest("API key invalid")

request.uid = user_id


And then use it

@http.route(..., auth='my_api_key', ...)


For requests, you just need to set the "Authorization: <api_key>" Header.


(Feedback appreciated)


3
Portretas
Atmesti
Luke

Where should this class go? I've tried putting in my controller file but it's causing a 500 server error.

Michael Jurke

@Luke the "ir.http" is a model to be put in the /models directory. You just extend the default Odoo "ir.http" model with your API authentication.

Nicky

Thank you Michael Jurke,
your Explanation is the correct one 👍
In Odoo V14/15 are following auth options existing by default without additional apps:
thing, calendar, outlook, public, user, none

Benjamin Damour

Thank you for your reply, it helps a lot.
FYI on V16 we should use request.update_env(user_id) instead of the request.uid = user_id

Portretas
Usman Farzand
Autorius Best Answer

yes thanks i found solution to pass api key from header its working now




@http.route('/my_service', auth='api_key', type='http')
def api_get_video(self, code):
2
Portretas
Atmesti
Portretas
Eric
Best Answer

This implementation below enables you to use a decorator without further inheritances.

from odoo import SUPERUSER_ID

from odoo.exceptions import ValidationError as VE

from odoo.http import request, db_list


  1. Decorator

def authenticate(func):

    @wraps(func)

    def validate_api_key(*args, **kw):

        auth_error = messages.get('access')

        key = request.httprequest.headers.get('api-key')

        if not key:

            raise VE(auth_error)

        if not request.session.db:

            request.session.db = db_list()[0]  # here we pick the first available db if the instance is a multi db and db_name has not been set in the odoo.conf

        uid = request.env['res.users.apikeys'].with_user(SUPERUSER_ID)._check_credentials(scope='rpc', key=key)

        if not uid:

            logger.error(f"{func.__name__} auth_error['message']")

            raise VE(auth_error)

        request.update_env(user=uid)  # here we switch the user to the one owning this key

        return func(*args, **kw)

    return validate_api_key


2. Controller

    @authenticate

    @route(['/products'], auth="public", type='json', methods=['POST'], csrf=False)

    def create_product(self, **kw):


0
Portretas
Atmesti
Portretas
Jesús María Jurado Núñez
Best Answer

@Luke, try to change @classmethod by @property, for me it works. Thanks @Michael for sharing.


Sorry again @Luke, but @Michael 's code is right but you have to consider putting it as a model, I was confused, maybe like you, and I wrote it into the controller but that's wrong.

0
Portretas
Atmesti
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registracija
Related Posts Replies Rodiniai Veikla
Error when trying to authenticate through API (v14) Solved
authentication api
Portretas
Portretas
Portretas
Portretas
Portretas
5
gruod. 20
11654
Question about how to authentication using api key Solved
authentication api api-key
Portretas
Portretas
1
rugs. 25
4891
API authentication not working with API key
authentication api api-key
Portretas
0
saus. 24
4046
How to authenticate users from res.users model in laradoo package
authentication api odoo
Portretas
0
liep. 21
4325
Has anyone integrated Helpdesk with Zoom for meeting scheduling?
api
Portretas
Portretas
1
rugp. 25
1284
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now