locked
HTTP POST Body parameters to get OAuth2 token RRS feed

  • Question

  • Hello,

    I'm trying to get Oauth2 token via http post but there is not clear way on how to add body parameters to request.

    Maybe someone could share if this functionality is available in Logic Apps or not?

    I've tried several ways but without success. 

    1st try

    "body": {
    	"grant_type": "password", 
    	"username": "zzzz",
    	"password": "zzzz",
    	"client_id": "guid",
    	"resource": "https://analysis.windows.net/powerbi/api",
    	"client_secret":"secret"        
    }
    2nd try
    "body": {
    	"parameters":{
    		"grant_type": "password", 
    		"username": "zzzz",
    		"password": "zzzz",
    		"client_id": "guid",
    		"resource": "https://analysis.windows.net/powerbi/api",
    		"client_secret":"secret"
    		}  
    	}
    Result
    "body": {
    "error": "invalid_request",
    "error_description": "AADSTS90014: The request body must contain the following parameter: 'grant_type'.",
    "error_codes": [
                90014
            ]

    Meanwhile I can get token via c# console app or Postman utility.

    Tuesday, January 19, 2016 8:47 AM

Answers

  • My guess is that usually OAuth expects the body to be formatted as form-data or x-www-form-urlencoded.  The Logic App HTTP Action just creates a raw body.  So you are passing:

    { "grant_type": "password",  "username": "zzzz", "password": "zzzz", "client_id": "guid", "resource": "https://analysis.windows.net/powerbi/api", "client_secret":"secret"         }

    as the body and it expects something that looks more like 

    grant_type=password&username=zzzz&password=zzzz.....

    with the correct content-type header.

    So I believe (assuming the service supports password grant type) if you reformat the body to be form-encoded it should work.

    Tuesday, January 19, 2016 6:27 PM

All replies

  • My guess is that usually OAuth expects the body to be formatted as form-data or x-www-form-urlencoded.  The Logic App HTTP Action just creates a raw body.  So you are passing:

    { "grant_type": "password",  "username": "zzzz", "password": "zzzz", "client_id": "guid", "resource": "https://analysis.windows.net/powerbi/api", "client_secret":"secret"         }

    as the body and it expects something that looks more like 

    grant_type=password&username=zzzz&password=zzzz.....

    with the correct content-type header.

    So I believe (assuming the service supports password grant type) if you reformat the body to be form-encoded it should work.

    Tuesday, January 19, 2016 6:27 PM
  • That actually did the trick. Header solved this. Thanks a lot Jeff.

    {
        "uri": "https://login.windows.net/common/oauth2/token",
        "method": "POST",
        "headers": {
            "Content-Type": "application/x-www-form-urlencoded"
        },
        "body": "grant_type=password&username=zzzz&password=zzz&client_id=guid&resource=https://analysis.windows.net/powerbi/api&client_secret=secret"
    }


    • Edited by Aivars_S Wednesday, January 20, 2016 7:57 AM
    Wednesday, January 20, 2016 7:54 AM
  • Reveiving below error while calling lcsapi while performing database restore
    {
    "IsSuccess": false,
    "OperationActivityId": "fa2e0692-18de-4e79-bdf1-008c55f27f93",
    "ErrorMessage": "Object reference not set to an instance of an object.",
    "VersionEOL": "9999-12-31T23:59:59.9999999"
    }

    Friday, December 13, 2019 3:10 PM