Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
42532 Lượt xem

Hello

I want test odoo 12 authentication in postman.In postman I am creating httprequest as POST method. first request check session with url http://localhost:8089/web/session/authenticate and second request check create customer with url http://127.0.0.1:8089/api/create_customer. 

Question: I want create customer after session authentication. but if running  single request i.e http://127.0.0.1:8089/api/create_customer in postman. customer is created without authentication. 


--EDIT--

please also give me information about auth_oauth module. difference between auth_oauth and auth_signup.                                       

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Authentication in odoo is achieved with a simple http header or a cookie.

To authenticate you need set the cookie "session_id", postman is smart enough to do that for you just like a browser.


First create a new request with the following:

http method: GET

url: http://localhost:8069/web/session/authenticate
headers: Content-Type: application/json
body: 

{
    "jsonrpc": "2.0", 
    "params": {
        "db": "v14pos", 
        "login": "admin", 
        "password": "admin"
    }
}

The body type should be "raw" in postman.

Of courser change the db, login(username/email), and password to your values.


Send the request, and if successful Odoo will response with information about the user, and the response header will include "Set-Cookie" which tells postman to set the session_id cookie.

Finally you can call any other url that requires authentication. Just make sure the base url is the same as the authentication request, so that postman will send the session_id cookie in the request.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

For authenticating Odoo From Postman, see this video showing the same: https://www.youtube.com/watch?v=wGvuRbCyytk


Thanks

Ảnh đại diện
Huỷ bỏ

link is not working Niyas?

Câu trả lời hay nhất

It's difficult to simulate odoo authentication using postman due to odoo protect all the post request using  Cross-Site Request Forgery (CSRF). you don't have csrf token while making post request so it rejects by odoo.

so first you have to make get a request to get csrf token(a token is embedded inside Html form ) and send it while you make a post request. (I don't know how to get it using postman). 

an alternative is after login through web browser copy the session_id and stores it postman cookie so all the next jsonrpc/AJAX/xhr request validate by the server and it works (I know it's not your requirement ;)

all the auth_* modules are not dependant on each other. it's named as auth_* because it's related to user authentication.

BTW why don't you use xml-rpc instead of a postman. it's very easy to authenticate and you can perform any operation using it. 

Ảnh đại diện
Huỷ bỏ
Tác giả

you are right. I have create request for acces_token. after getting access-token and passing this into postman my issue is solve.thanks for you time and suggestion.

Câu trả lời hay nhất

Hi everybody. Thanks to Obay for your help, this is my javascript auth from postman. I hope to help you.

var data = JSON.stringify({
"jsonrpc": "2.0",
"params": {
"db": "your_data_base_name",
"login": "your_user_name",
"password": "your_password"
}
});

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});

xhr.open("POST", "http://localhost:8069/web/session/authenticate");
xhr.setRequestHeader("Content-Type", "application/json");

xhr.send(data);

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 8 22
2280
5
thg 5 25
33521
0
thg 11 23
1753
2
thg 5 23
10510
3
thg 8 20
10280