콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
4 답글
42288 화면

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.                                       

아바타
취소
베스트 답변

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.

아바타
취소
베스트 답변

Hi,

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


Thanks

아바타
취소

link is not working Niyas?

베스트 답변

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. 

아바타
취소
작성자

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.

베스트 답변

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);

아바타
취소
관련 게시물 답글 화면 활동
0
8월 22
2261
5
5월 25
33354
0
11월 23
1705
2
5월 23
10437
3
8월 20
10230