Skip to Content
Odoo Meny
  • Sign in
  • Prova gratis
  • Appar
    Finanstjänster
    • Bokföring
    • Fakturering
    • Utgifter
    • Kalkylark (Affärsanalyser)
    • Dokument
    • Underskrifter
    Försäljning
    • CRM
    • Försäljning
    • Kassasystem Butik
    • Kassasystem Restaurang
    • Prenumerationer
    • Uthyrning
    Hemsidor
    • Hemsidesverktyg
    • E-handel
    • Blogg
    • Forum
    • Livechatt
    • Utbildning
    Försörjningskedja
    • Lager
    • Produktion
    • Produktens livscykel (PLM)
    • Inköp
    • Underhåll
    • Kvalitet
    HR
    • Anställda
    • Rekrytering
    • Ledighet
    • Utvärderingar
    • Rekommendationer
    • Fordon
    Marknadsföring
    • Sociala medier
    • E-postmarknadsföring
    • Sms-marknadsföring
    • Evenemang
    • Automatiserad marknadsföring
    • Enkäter
    Tjänster
    • Projekt
    • Tidrapporter
    • Fältservice
    • Kundtjänst
    • Planering
    • Tidsbokningar
    Produktivitet
    • Diskutera
    • Godkännanden
    • IoT
    • VoIP
    • Kunskap
    • WhatsApp
    Community-appar Odoo Studio Odoo Cloud
  • Branscher
    Butiker
    • Bokaffärer
    • Klädbutiker
    • Möbelaffärer
    • Mataffärer
    • Byggvaruhus
    • Leksaksaffärer
    Restaurang & Hotell
    • Barer och pubar
    • Gourmetrestauranger
    • Snabbmatsrestauranger
    • Gästhus
    • Dryckesdistributörer
    • Hotell
    Fastigheter
    • Fastighetsbyråer
    • Arkitektfirmor
    • Byggföretag
    • Fastighetsägare
    • Trädgårdsmästare
    • Bostadsrättsföreningar
    Hitta en konsult
    • Redovisningsbyrå
    • Odoo Partner
    • Reklambyråer
    • Advokatbyråer
    • Rekrytering
    • Revisioner och certifieringar
    Produktion
    • Textilproduktion
    • Metallproduktion
    • Möbelproduktion
    • Livsmedelsproduktion
    • Bryggerier
    • Företagsgåvor
    Hälsa & Fitness
    • Sportklubbar
    • Optiker
    • Träningscenter
    • Hälsovård
    • Apotek
    • Frisörsalonger
    Hantverk
    • Hantverkare
    • IT-utrustning och kundtjänst
    • Solenergi
    • Skomakare
    • Städtjänster
    • VVS-tjänster
    Övrigt
    • Ideella föreningar
    • Miljöförvaltningar
    • Uthyrning av reklamtavlor
    • Fotografer
    • Cykeluthyrning
    • Återförsäljare av mjukvara
    Upptäck alla Branscher
  • Community
    Utbildning
    • Instruktionsvideor
    • Dokumentation
    • Certifiering
    • Utbildningar
    • Blogg
    • Podcast
    Lär dig med oss
    • Workshops
    • Företagsspelet Scale Up!
    • Studiebesök hos Odoo
    Mjukvaran
    • Ladda ner
    • Jämför utgåvor
    • Tidigare versioner
    Samverkan
    • GitHub
    • Forum
    • Evenemang
    • Översättningar
    • Bli en partner
    • Partnertjänster
    • Registrera din redovisningsbyrå
    Våra tjänster
    • Partners
    • Revisorer
    • Träffa en rådgivare
    • Implementering
    • Kundrecensioner
    • Kundtjänst
    • Uppgraderingar
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Boka en demo
  • Priser
  • Hjälp
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

JSON API, API Keys and user connection

Subscribe

Get notified when there's activity on this post

This question has been flagged
authenticationapi
2 Replies
1167 Views
Avatar
Martin

We'd like to develop a mobile app linked to a Odoo (19). Our goal is to use the JSON API, both because it seems to be the way of the future and also because we're more familiar with that kind of tech.


We have something that we can't figure out. Our goal is to have our end user to identify with their login/password in the app, and then use their credential to use the API (for example to retrieve their current holidays).

Issue: this works only using the API key, which cannot be generated from an endpoint - even with the user's password.

What's the current advice/strategy in this case? We could have a technical user with high access and use it everywhere but it looks extremely dangerous and actually not practical (I want to retrieve the current user's holiday, not all of them, etc).


People here making mobile apps, how are you interacting with the new API?

0
Avatar
Discard
Martin
Author

Thanks - I get the idea but your example is using the jsonrpc api - I don't see any way to use this "with_user "on the json2 ("rest") one.

Ray Carnes (ray)

https://www.odoo.com/documentation/19.0/developer/reference/external_api.html#object-service

Avatar
Cybrosys Techno Solutions Pvt.Ltd
Best Answer
Hi,

You're encountering a frequent issue when integrating Odoo 19 JSON-RPC API with mobile app user authentication. Since API keys are not suitable for individual mobile users authenticating with personal credentials, the correct solution is session-based authentication.
Why session-based authentication is ideal for mobile apps

    Users log in using their own username and password

    User context is automatically applied (no need to pass user ID manually)

    Access rights, record rules, and ACLs are enforced correctly

    No need to generate or maintain API keys for each user

Authenticate from the mobile app

Send a POST request to the Odoo session authentication endpoint:

POST https://your-odoo-instance.com/web/session/authenticate

Content-Type: application/json

Request payload:

{
    "jsonrpc": "2.0",
    "params": {
        "db": "your_database",
        "login": "user@example.com",
        "password": "user_password"
    }
}

If authentication succeeds:

    Odoo returns session_id

    The session_id is also set in response cookies

Store session_id securely in your mobile app

Use platform-specific secure storage:
Create a custom authenticated API endpoint in Odoo

In your custom Odoo module, define a controller with auth="user":

from odoo import http

class MobileHolidaysController(http.Controller):

    @http.route('/api/mobile/my/holidays', type='json', auth='user')
    def get_my_holidays(self, **kwargs):
        # Business logic goes here
        return {
            "status": "success",
            "message": "Authenticated successfully",
            "data": {}  # Replace with your actual holiday records
        }
Call the endpoint from the mobile app

Include the stored session_id in cookies for all requests:

POST https://your-odoo-instance.com/api/mobile/my/holidays

Cookie: session_id=your_stored_session_id
Content-Type: application/json

Payload:

{
    "jsonrpc": "2.0",
    "params": {}
}


Hope it helps

0
Avatar
Discard
Avatar
Ray Carnes (ray)
Best Answer

with_user might be helpful here

self.env['hr.leave'].with_user(mobile_user).search([])

https://www.odoo.com/forum/help-1/what-is-the-purpose-of-with-user-means-what-is-the-advantage-of-using-it-189340

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
How i can auth my user to access odoo with API Key or Access Token? Solved
authentication api
Avatar
Avatar
Avatar
Avatar
4
aug. 24
46081
Error when trying to authenticate through API (v14) Solved
authentication api
Avatar
Avatar
Avatar
Avatar
Avatar
5
dec. 20
12291
Question about how to authentication using api key Solved
authentication api api-key
Avatar
Avatar
1
sep. 25
6920
API authentication not working with API key
authentication api api-key
Avatar
0
jan. 24
4862
How to authenticate users from res.users model in laradoo package
authentication api odoo
Avatar
0
juli 21
4726
Community
  • Instruktionsvideor
  • Dokumentation
  • Forum
Öppen källkod
  • Ladda ner
  • GitHub
  • Runbot
  • Översättningar
Tjänster
  • Odoo.sh Hosting
  • Kundtjänst
  • Uppgradera
  • Anpassningsbara modifikationer
  • Utbildning
  • Revisorer
  • Partners
  • Bli en partner
Om oss
  • Vårt företag
  • Varumärkestillgångar
  • Kontakta oss
  • Jobb
  • Evenemang
  • Podcast
  • Blogg
  • Kunder
  • Juridiskt • Integritet
  • Säkerhet
الْعَرَبيّة 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 Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo är ett affärssystem med öppen källkod som täcker alla dina företagsbehov: CRM, e-handel, bokföring, lager, kassasystem, projektledning, och så vidare.

Odoos unika värdeförslag är att samtidigt vara väldigt enkel att använda men också helt integrerad.

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