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

  • Thank you so much for this debug info @woganmay

     

    Yes I've tried adding the header exactly as you mentioned above, and I also couldn't get it to work. I'll check with the Domo developer folks when they get back to me. Thanks again.

     

    Best,

    Adi 

  • kshah008
    kshah008 Contributor

    @apothuri, please keep us posted!

  • 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. 

  • hey@apothuri!

     

    Did you figure out how to solve it?I have a very simillar issue...

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

  • 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.

     

     

  • You need to convert the postData object to a JSON string before sending the httprequest.

    you can do that with JSON.stringify(postData)

     

This discussion has been closed.