I am trying to connect Magento 2 Integration system / Web APIs with ERPNext OAuth Client. Unfortunately I always have the error:
By using google, I found that most of this issues occur, because the Content-Type header of the request is empty. In this case, it’s true as well; but I can not imagine that there is a problem in Magento 2, neither in ERPNext.
After long time trial and error, I was hoping that someone might know how to configure it properly:
In Magento 2, I have the following
Are the URLs in the right order?
In ERPNext, I have the following:
Before investigating more, I just wanted to be sure, that I am on the right track. Maybe I am misunderstanding something very basic and someone might lead me to the right direction.
Thank you very much.
Frappe framework supports OAuth 2.0,
Authorization Code Grant/Bearer Token(access/refresh) flow
and Implicit Grant/Token (access) flow
By default magento only supports OAuth 1.0a, some customization is available for OAuth 2.0
Note: OAuth 1 can be brought into frappe. OAuthlib library is available Creating a Provider — OAuthLib 3.2.1 documentation
Google Oauth 2.0 Client for magento GitHub - mage2pro/google-backend-login: The «Backend Login with Google Account» extension for Magento 2
@ci2016 What are your plans for this connector? We are working on this also but would rather not duplicate effort if you’re already further along. Can we contribute somehow?
Briefly OAuth 2.0 Authorization Code Grant/Bearer Token(access/refresh) flow:
- There is a button which initiates a get request in browser. e.g. In this case there must be a button on Magento’s Screen for access frappe resource.
- The response of this request is redirect to the specified redirect url in Oauth Client.
- Code is sent to the specified url. (in this case it’ll be an endpoint on magento side)
- This endpoint on magento server will take the code and request to get_token endpoint on frappe server.
@ci2016 OAuth 2 Client’s Redirect URIs must be on magento.custom.work and not erp.custom.work
- Response of this get_token endpoint is bearer token, which can be used to access resource on frappe server.
- To complete “Login with” thing. Magento must call openid_profile endpoint with access token in header and get the details of the user. Use this user details to create or update user linked in magento.
- If “login with” is not required, just use the access token to get resources from frappe server.
Frappe Oauth 2 Documentation:
At the moment I was writing the post, I was trying to achieve a connection between Magento 2 and ERPNext. I assumed Magento 2 has OAuth2 (which it doesn’t) and that Magento 2 supports Webhooks (which it doesn’t as well).
My plan was to simply push all data which is coming into Magento 2, for example orders, products etc. to ERPNext (preferably as JSON) and save it to the right doctype.
Since Magento 2 doesn’t support OAuth 2 and doesn’t have Webhooks at all, I think the smartest way is just to pull all the data every hour by a custom app.
By the way: theres a community approach to bring webhooks to Magento 2, which uses Observers, but it doesn’t have a lot of contributors and it’s not very advanced in the moment. If you wan’t to have a closer look, heres the Github link.
We should connect anyway. I’ll keep you updated.