Domo Connector - Oauth2.0 question
So I'm building a connector using the developer IDE, but I just can't seem to get the authentication script working with the 'httprequest' library (I believe it's domo built-in?)
The connector will serve to pull data from my API and the API uses Oauth2.0. However, I'm having trouble getting a token through domo, but I can easily do it through a curl or by using Postman API tool.
I'm getting a HTTP 415 - Unsupported Media Type Error
Here's the code below:
var client_id = '4969e1ea-71b9-3267-ae7d-4ce0ac6bfa28';
var client_secret = '*****************************';
var user = '*********';
var pass = '*********';
var postData =
{
data: {
'grant_type': 'password',
'username': user,
'password': pass,
'client_id': client_id,
'client_secret': client_secret,
'scope': 'internal'
}
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
var res = httprequest.post('https://rest.synthesio.com/security/v1/oauth/token', postData);
DOMO.log('res: ' + res);
Please let me know if you have a different way of approaching this. I've tried to remove the headers within the postdata object itself as well as removing the data variable, leaving the attributes as is, too.
Thanks,
Adi
Comments
-
It doesn't look like Domo is respecting that header field. I used your code to hit a debug endpoint of mine, and this is what came through:
Array
(
[_SERVER] => Array
(
[CONTENT_TYPE] => application/json; charset=utf-8
[CONTENT_LENGTH] => 261
[HTTP_USER_AGENT] => okhttp/3.2.0
[REQUEST_SCHEME] => https
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => POST
)
[_POST] => Array
(
)
[_GET] => Array
(
)
[raw] => {"data":{"grant_type":"password","username":"*********","password":"*********","client_id":"4969e1ea-71b9-3267-ae7d-4ce0ac6bfa28","client_secret":"*****************************","scope":"internal"},"headers":{"Content-Type":"application/x-www-form-urlencoded"}}
)The content type is coming through as JSON, and the raw content of the post is your entire JSON block, as-is, being sent through.
The documentation makes reference to a "addHeader" call, which theoretically should let you do this:
httprequest.addHeader('Content-Type', 'application/x-www-form-urlencoded');
var res = httprequest.post('https://.....', postData);Unfortunately that doesn't appear to work at all. The content type still comes through as JSON.
It'll be up to Domo to determine why:
1. addHeader() doesn't let you override the content type,
2. Why setting the type to form-encoded doesn't actually form-encode the request payload
0 -
This issue is still unresolved and Domo hasn't gotten back to me yet. Just need the correct approach from Domo because their httprequest library does not work for this. It's hard to believe that Oauth2.0 is not supported though.
0 -
0
-
This worked for me below:
httprequest.addParameter('grant_type', 'password');
httprequest.addParameter('username', user);
httprequest.addParameter('password', pass);
httprequest.addParameter('client_id', client_id);
httprequest.addParameter('client_secret', client_secret);
httprequest.addParameter('scope', 'read');var res = httprequest.post('https://rest.synthesio.com/security/v1/oauth/token');
DOMO.log('res.access_token: '+JSON.parse(res).access_token);0 -
can this be used to support authorization code responses (before obtaining the token)?
my resource I connect to requires an authorization code before obtaining an access token.
0 -
You need to convert the postData object to a JSON string before sending the httprequest.
you can do that with JSON.stringify(postData)
0
Categories
- All Categories
- 1.8K Product Ideas
- 1.8K Ideas Exchange
- 1.6K Connect
- 1.2K Connectors
- 300 Workbench
- 6 Cloud Amplifier
- 9 Federated
- 2.9K Transform
- 102 SQL DataFlows
- 626 Datasets
- 2.2K Magic ETL
- 3.9K Visualize
- 2.5K Charting
- 754 Beast Mode
- 61 App Studio
- 41 Variables
- 693 Automate
- 178 Apps
- 456 APIs & Domo Developer
- 49 Workflows
- 10 DomoAI
- 38 Predict
- 16 Jupyter Workspaces
- 22 R & Python Tiles
- 398 Distribute
- 115 Domo Everywhere
- 276 Scheduled Reports
- 7 Software Integrations
- 130 Manage
- 127 Governance & Security
- 8 Domo Community Gallery
- 38 Product Releases
- 11 Domo University
- 5.4K Community Forums
- 40 Getting Started
- 30 Community Member Introductions
- 110 Community Announcements
- 4.8K Archive