OAUTH Token Request using Azure AD

jeighsohnjeighsohn Member Posts: 14
First off, I was able to create a working call in Postman and received back a token, however, I can't seem to make it work in NAV2013. In Postman, I can use form-data or x-www-form-urlencoded, but neither seems to work in NAV. I either get a Bad Request (400), or connection forcibly reset by host error. Any tips?
  OAuthReq := STRSUBSTNO(OAuthReqTxt,recILSSetup."API Conf Client ID",recILSSetup."API Conf Client Secret",recILSSetup."API Resource ID");
  sb := sb.StringBuilder();
  sb.Append(OAuthReq);

  UTFEncoding := UTFEncoding.UTF8Encoding;
  JsonLength := UTFEncoding.GetBytes(sb.ToString).Length;   

  HttpWebRequest := HttpWebRequest.Create(STRSUBSTNO(recILSSetup."OAUTH URL",recILSSetup."Tenant ID"));
  HttpWebRequest.Timeout := 30000;
  HttpWebRequest.Method := 'POST';
  HttpWebRequest.ContentType:= 'application/form-urlencoded'; //'multipart/form-data'; //'application/x-www-form-urlencoded';
  ServicePointManager.SecurityProtocol(SecurityProtocol.Tls12);  //Need to define encryption to prevent Web Service from rejecting request
  ResponseStream := HttpWebRequest.GetRequestStream;
  ResponseStream.Write(UTFEncoding.GetBytes(sb.ToString),0,JsonLength);
  ResponseStream.Close;

  HttpWebResponse := HttpWebRequest.GetResponse;  //ALWAYS FAILS HERE

Answers

  • jeighsohnjeighsohn Member Posts: 14
    Turns out - the issue was not in my code, but rather in the shared secret. NAV was auto-truncating the secret value I was pasting into the configs table. :(
Sign In or Register to comment.