İçereği Atla
Odoo Menü
  • Portal
  • Ücretsiz deneyin
  • Uygulamalar
    Finans
    • Muhasebe
    • Faturalama
    • Masraf Yönetimi
    • Elektronik Çizelge (BI)
    • Belgeler
    • İmza
    Satış
    • Müşteri İlişkileri Yönetimi (CRM)
    • Satış
    • Satış Noktası Mağaza
    • Satış Noktası Restoran
    • Abonelikler
    • Kiralama
    Web Sitesi
    • Web Sitesi Oluşturucu
    • eTicaret
    • Blog
    • Forum
    • Canlı Sohbet
    • eÖğrenme
    Tedarik Zinciri
    • Envanter
    • Üretim
    • Ürün Yaşam Döngüsü Yönetimi
    • Satın Alma
    • Bakım
    • Kalite
    İnsan Kaynakları
    • Çalışanlar
    • İşe Alım
    • İzin
    • Değerlendirme
    • Referans
    • Filo Yönetimi
    Pazarlama
    • Sosyal Medyada Pazarlama
    • E-posta ile Pazarlama
    • SMS ile Pazarlama
    • Etkinlikler
    • Pazarlama Otomasyonu
    • Anket
    Hizmetler
    • Proje Yönetimi
    • Çalışma Çizelgeleri
    • Saha Hizmeti
    • Yardım Masası
    • Planlama
    • Randevular
    Verimlilik
    • Sohbet
    • Onay
    • Nesnelerin İnterneti
    • VoIP
    • Bilgi Bankası
    • WhatsApp
    Üçüncü taraf uygulamalar Odoo Stüdyo Odoo Bulut Platformu
  • Sektörler
    Perakende satış
    • Kitapçı
    • Giyim Mağazası
    • Mobilya Mağazası
    • Gıda Marketi
    • Hırdavat Dükkanı
    • Oyuncak Dükkanı
    Gıda ve Konaklama
    • Bar ve Pub
    • Restoran
    • Fast Food Restoranı
    • Konuk Evi
    • İçecek Distribütörü
    • Otel
    Gayrimenkul
    • Emlak Acentesi
    • Mimarlık Firması
    • İnşaat
    • Emlak Yönetimi
    • Bahçe Tasarımı
    • Mülk Sahipleri Derneği
    Uzmanlık
    • Muhasebe Firması
    • Odoo Partner
    • Pazarlama Ajansı
    • Hukuk Firması
    • Yetenek Kazanımı
    • Denetim ve Belgelendirme
    Üretim
    • Tekstil
    • Metal
    • Mobilyalar
    • Gıda
    • Bira fabrikası
    • Kurumsal Hediye
    Sağlık ve Spor
    • Spor Kulübü
    • Optik Mağazası
    • Fitness Merkezi
    • Sağlıklı Yaşam Merkezi
    • Eczane
    • Kuaför Salonu
    Ticaret
    • Tamirci
    • BT Donanım & Destek
    • Güneş Enerjisi Sistemleri
    • Ayakkabı İmalatçısı
    • Temizlik Hizmetleri
    • HVAC Hizmetleri
    Diğerleri
    • Kar Amacı Gütmeyen Kuruluş
    • Çevre Ajansı
    • Reklam Panosu Kiralama
    • Fotoğrafçılık
    • Bisiklet Kiralama
    • Yazılım Bayisi
    Tüm Sektörlere Göz Atın
  • Topluluk
    Öğrenim
    • Eğitim Araçları
    • Dokümantasyon
    • Sertifikasyonlar
    • Eğitim Etkinlikleri
    • Blog
    • Podcast
    Eğitim ve Gelişim
    • Eğitim Programı
    • Scale Up! İşletme Oyunu
    • Odoo'yu Ziyaret Edin
    Yazılım
    • İndirin
    • Sürümleri Kıyaslayın
    • Sürümler
    İş Birliği
    • Github
    • Forum
    • Etkinlikler
    • Çeviriler
    • Partner Olun
    • Partnerler için Hizmetler
    • Muhasebe Firmanızı Kaydettirin
    Hizmetler
    • Partner Bulun
    • Muhasebeci Bulun
    • Bir danışmanla görüşün
    • Kurulum Hizmetleri
    • Müşteri Referansları
    • Destek
    • Sürüm Yükseltme
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Demo randevusu alın
  • Fiyatlandırma
  • Yardım

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

  • Müşteri İlişkileri Yönetimi
  • e-Commerce
  • Muhasebe
  • Envanter
  • PoS
  • Proje Yönetimi
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiketler (View all)
odoo accounting v14 pos v15
About this forum
Yardım

How to create a custom controller with user authentication - Odoo13?

Abone Ol

Get notified when there's activity on this post

Bu soru işaretlendi
authenticationusercontrollers
8 Cevaplar
26069 Görünümler
Avatar
Kabeer KB

I am trying to create a custom controller with user authentication.
Here is what i did.

        class GetUserDetails(http.Controller):
        @http.route('/web/getUserDetail',auth='user',type='json')
        def getChit(self,**kw):
            print('Inside getUser detail',kw)

Issue 1: When i call this controller from an API client (ARC) its directly get into that function, without any authentication.???

Issue 2: If we solved the above issue, how can i authenticate a user via API call/client.

Actually i want to get user details in android app.

1
Avatar
Vazgeç
Avatar
Yenthe Van Ginneken (Mainframe Monkey)
En İyi Yanıt

Hi,

If you want to call a controller with auth='user' you should first get your user id and session_id and then continue from there. You can get the session_details from /web/session/authenticate like this:

session_details = requests.get(url=odoo_url + '/web/session/authenticate', data=json.dumps(data_string), headers=headers)
session_id = str(session_details.cookies.get('session_id'))

Once you have the session details you can set your cookies/values and call the endpoint:

cookies = {
'username': db_username,
'password': db_password,
'session_id': session_id // which we just got in the previous code block
}
requests.get(url=odoo_url + '/web/getUserDetail', params=params, headers=headers, cookies=cookies)

Regards,
Yenthe

1
Avatar
Vazgeç
Kabeer KB
Üretici

@ Yenthe, i got the session id and i tried to call the url as per your solution but getting this error `Function declared as capable of handling request of type 'json' but called with a request of type 'http'`.

Yenthe Van Ginneken (Mainframe Monkey)

That happens when you call the controller with the wrong type or data. Make sure you're doing a get request which has the parameters, headers and cookies and that it contains JSON.

SOUJIRO30

Is it available in Odoo 14?

Osama Hassan

we need to reassign user and pass in cookies as well ?? if we authenticate

Avatar
TravisScott
En İyi Yanıt

To create a custom controller with user authentication in Odoo 13, define your controller class using @http.route and implement the @http.auth decorator for user access. Ensure to handle session management and access rights in your methods accordingly.

0
Avatar
Vazgeç
Avatar
Vasiliy "hoshiyoumu" Kuznetsov
En İyi Yanıt

As I was searching for Odoo user authentication via Postman and this thread was the best matching result I want to share resulting minimal example

Hopes it will help somebody

Environment: containerized Odoo17

import yaml

from odoo import http, Command
from odoo.http import request

class ExampleController(http.Controller):
@http.route('/api/v1/example/', type='json', auth='user', methods=['POST'], csrf=True)
def create_example(self):
kwargs = yaml.load(request.httprequest.data) # incoming json data
resp = some_internal_function(kwargs)
return resp


Authentication request in postman

http://127.0.0.1:8069/web/session/authenticate

Headers: Content-Type: application/json Body: (raw/JSON)

{
"params": {
"db": "my_odoo_dbname",
"login": "user",
"password": "their_password"
}
}

If succeed, in response there will be Cookies section. <>
Copy session_id​ key


Authenticated request in postman

http://127.0.0.1:8069/api/v1/example/

Headers: Content-Type: application/json/
Cookie: session_id=YOURSESSIONID Body: (raw/JSON)
YOUR JSON BODY
0
Avatar
Vazgeç
Avatar
ChunYi Fu
En İyi Yanıt

I have the same problem now, looks like odoo removed session concept since some release.  So the web client session never expires, and there is no session in json-rpc interface at all, only user id is used there.  Did you guys use session id finally?

0
Avatar
Vazgeç
Avatar
Alan Luo
En İyi Yanıt

default on odoo 13 there is no session_id response, but you can add it manual by add:

it from addons: 'Auth Session Info' by Hariprasath.B

# -*- coding: utf-8 -*-

from odoo import models
from odoo.http import request


class Http(models.AbstractModel):
_inherit = 'ir.http'

def session_info(self):
res = super(Http, self).session_info()
if not res.get('session_id'):
# Add Session Id
res['session_id'] = request.session.sid
return res
0
Avatar
Vazgeç
Avatar
Anand Raja K
En İyi Yanıt

@Niyas , the response is as you got. But if you try session_details.cookies.get('session_id') will get session_id definitely.

0
Avatar
Vazgeç
Avatar
it@mycb1.com
En İyi Yanıt

In Odoo 13 the session_id is in cookies

0
Avatar
Vazgeç
Avatar
Niyas Raphy (Walnut Software Solutions)
En İyi Yanıt

Hi,

As the auth='user' is given,  the route the controller will be accessible only for the authenticated users, else it will show some invalid or session_expired response .


Issue 1: I have checked some custom functions using the postman application and it seems working fine with auth='user' , if there is no valid session_id it will ask to authenticate first. In your case can you try the same with the postman application and confirm.

Issue 2: For authentication use the controller, /web/session/authenticate .


See the detailed Video Here: Authentication, Fetching Data & Creating Records Using Controller


Thanks

0
Avatar
Vazgeç
Kabeer KB
Üretici

@Niyas, Thanks for the answer.

I tried to gt session by calling `http://localhost:5013/web/session/authenticate`. in the response, i couldn't find `sessino_id`.

here is the output.

{

"jsonrpc": "2.0",

"id": null,

"result": {

"uid": 2,

"is_system": true,

"is_admin": true,

"user_context": {

"lang": "en_US",

"tz": false,

"uid": 2

},

"db": "demo_odoo13",

"server_version": "13.0-20191007",

"server_version_info": [

13,

0,

0,

"final",

0,

""

],

"name": "Administrator",

"username": "admin",

"partner_display_name": "Administrator",

"company_id": 1,

"partner_id": 3,

"user_companies": {

"current_company": [

1,

"My Company"

],

"allowed_companies": [

[

1,

"My Company"

]

]

},

"currencies": {

"1": {

"symbol": "€",

"position": "after",

"digits": [

69,

2

]

},

"2": {

"symbol": "$",

"position": "before",

"digits": [

69,

2

]

}

},

"web.base.url": "http://localhost:5013",

"show_effect": "True",

"display_switch_company_menu": false,

"cache_hashes": {

"load_menus": "b7ea4d99293455ecb82c8d87efd5653792dc22b7",

"qweb": "befe30ca4d3deb2880b68d2532163699398dba61",

"translations": "026ae15487c2067877f7b82ffb991974c070d399"

},

"web_tours": [],

"out_of_office_message": false,

"odoobot_initialized": true

}

}

Kabeer KB
Üretici

@ Niyas, I tried with post man, but the same result, i can access it without session_id. When i print `request.env.user.name` it Prints `Administrator`.

Prakash

@Niyas I have query related to api posted in the odoo forum please check this link https://www.odoo.com/forum/help-1/api-get-model-data-with-particular-user-only-190580

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

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

Üye Ol
İlgili Gönderiler Cevaplar Görünümler Aktivite
How to connect a users instead of login process? Çözüldü
authentication user
Avatar
Avatar
1
Eyl 21
2697
Custom controller route with no authentication Çözüldü
authentication controllers odoo10.0
Avatar
Avatar
4
Oca 19
3901
Custom authentication, javascript never call
javascript authentication controllers contro
Avatar
1
May 17
5702
Form to authenticate new users (Login)
authentication form user login
Avatar
0
Eki 16
4500
Where is logged the default template user in python code?
authentication user template signup
Avatar
Avatar
1
Ağu 15
7602
Topluluk
  • Eğitim Araçları
  • Dokümantasyon
  • Forum
Açık Kaynak
  • İndirin
  • Github
  • Runbot
  • Çeviriler
Hizmetler
  • Odoo.sh Hosting
  • Destek
  • Sürüm Yükseltme
  • Özel Geliştirmeler
  • Eğitim
  • Muhasebeci Bulun
  • Partner Bulun
  • Partner Olun
Hakkında
  • Şirketimiz
  • Pazarlama Gereçleri
  • İletişim
  • Kariyer
  • Etkinlikler
  • Podcast
  • Blog
  • Müşteriler
  • Hukuki • Gizlilik
  • Güvenlik
الْعَرَبيّة 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, müşteri ilişkileri yönetimi, eTicaret, muhasebe, envanter, satış noktası, proje yönetimi gibi şirketinizin tüm ihtiyaçlarını karşılayan bir açık kaynak işletme uygulamaları paketidir.

Odoo’nun eşsiz değer önermesi, aynı anda hem kullanımının çok kolay olup hem de tamamen entegre olmasıdır.

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