11.5.1 HTTP REST Support for oAuth

Posted by carl.williams on 31-Jul-2015 07:19

I know out of the box the new HTTP Client does not support oAuth. Does anyone have an example oAuth implementation in Openedge or may be cURL? I want to connect to Magento via REST from Openedge and push up product and price changes. Thanks.

Posted by Peter Judge on 31-Jul-2015 07:52

I know of people using the http client for oauth with google  as provider. Some example code for that is below, as a guide to how you'd do some things.

The exact details of the flow (ie which operations to call in which order) and the arguments should be at http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html

block-level on error undo, throw.
 
using OpenEdge.Core.String.
using OpenEdge.Net.HTTP.ClientBuilder.
using OpenEdge.Net.HTTP.IHttpRequest.
using OpenEdge.Net.HTTP.IHttpResponse.
using OpenEdge.Net.HTTP.RequestBuilder.
 
/* ***************************  Main Block  *************************** */
define variable httpUrl      as character    no-undo.
define variable oRequest     as IHttpRequest no-undo.
define variable oResponse    as IHttpResponse no-undo.
define variable oRequestBody as String no-undo.
 
/*
POST https://www.googleapis.com/oauth2/v3/token HTTP/1.1
Content-type: application/x-www-form-urlencoded
Host: www.googleapis.com
client_id=your_client_id&client_secret=your_client_secret&refresh_token=your_refresh_token&grant_type=refresh_token
 
*/ 
 
session:debug-alert = true.
httpUrl = "https://www.googleapis.com/oauth2/v3/token".
 
oRequestBody = new String('client_id=your_client_id&client_secret=your_client_secret&refresh_token=your_refresh_token&grant_type=refresh_token').
 
oRequest = RequestBuilder:Post("https://www.googleapis.com/oauth2/v3/token", oRequestBody)
            :ContentType('application/x-www-form-urlencoded')
            :AcceptJson()
            :Request.
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
message
    oResponse:StatusCode  skip
    oResponse:StatusReason skip
    view-as alert-box.
 
    
request-raw.txt
POST /oauth2/v3/token HTTP/1.1
Host: www.googleapis.com
User-Agent: OpenEdge-HttpClient/0.3.0 (WIN32/64) OpenEdge/11.5.1.0.1190 Lib-ABLSockets/0.3.0
Accept: application/json
Content-Length: 115
Content-Type: application/x-www-form-urlencoded
 
client_id=your_client_id&client_secret=your_client_secret&refresh_token=your_refresh_token&grant_type=refresh_token
 


All Replies

Posted by Srinivas Munigala on 31-Jul-2015 07:26

OpenEdge REST doesn't support OAuth. For more information, please visit the following link:

knowledgebase.progress.com/.../Does-OpenEdge-REST-Services-support-OAuth-Bearer-Tokens

Posted by Peter Judge on 31-Jul-2015 07:52

I know of people using the http client for oauth with google  as provider. Some example code for that is below, as a guide to how you'd do some things.

The exact details of the flow (ie which operations to call in which order) and the arguments should be at http://www.magentocommerce.com/api/rest/authentication/oauth_authentication.html

block-level on error undo, throw.
 
using OpenEdge.Core.String.
using OpenEdge.Net.HTTP.ClientBuilder.
using OpenEdge.Net.HTTP.IHttpRequest.
using OpenEdge.Net.HTTP.IHttpResponse.
using OpenEdge.Net.HTTP.RequestBuilder.
 
/* ***************************  Main Block  *************************** */
define variable httpUrl      as character    no-undo.
define variable oRequest     as IHttpRequest no-undo.
define variable oResponse    as IHttpResponse no-undo.
define variable oRequestBody as String no-undo.
 
/*
POST https://www.googleapis.com/oauth2/v3/token HTTP/1.1
Content-type: application/x-www-form-urlencoded
Host: www.googleapis.com
client_id=your_client_id&client_secret=your_client_secret&refresh_token=your_refresh_token&grant_type=refresh_token
 
*/ 
 
session:debug-alert = true.
httpUrl = "https://www.googleapis.com/oauth2/v3/token".
 
oRequestBody = new String('client_id=your_client_id&client_secret=your_client_secret&refresh_token=your_refresh_token&grant_type=refresh_token').
 
oRequest = RequestBuilder:Post("https://www.googleapis.com/oauth2/v3/token", oRequestBody)
            :ContentType('application/x-www-form-urlencoded')
            :AcceptJson()
            :Request.
oResponse = ClientBuilder:Build():Client:Execute(oRequest).
message
    oResponse:StatusCode  skip
    oResponse:StatusReason skip
    view-as alert-box.
 
    
request-raw.txt
POST /oauth2/v3/token HTTP/1.1
Host: www.googleapis.com
User-Agent: OpenEdge-HttpClient/0.3.0 (WIN32/64) OpenEdge/11.5.1.0.1190 Lib-ABLSockets/0.3.0
Accept: application/json
Content-Length: 115
Content-Type: application/x-www-form-urlencoded
 
client_id=your_client_id&client_secret=your_client_secret&refresh_token=your_refresh_token&grant_type=refresh_token
 


This thread is closed