30. November 2022 13:06
[TryFunction]
LOCAL PROCEDURE GetAuthToken2@1000000130();
VAR
URL@1000000000 : Text;
RequestBody@1000000007 : Text;
myRequest@1000000014 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebRequest";
RequestStream@1000000016 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Stream";
AuthStreamWriter@1000000015 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.StreamWriter";
Encoding@1000000017 : DotNet "'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Text.Encoding";
myResponse@1000000018 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebResponse";
BEGIN
URL := 'https://login.microsoftonline.com/xxxxxxxxxxxxxxxxxxxxxxx/oauth2/token';
myRequest := myRequest.Create(URL);
myRequest.Method := 'POST';
myRequest.ContentType := 'application/x-www-form-urlencoded';
myRequest.Timeout := 30000;
RequestStream := myRequest.GetRequestStream();
RequestBody := 'client_id=xxxxxxxxxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials&redirect_uri=https%3A%2F%2Flocalhost&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default';
AuthStreamWriter := AuthStreamWriter.StreamWriter(RequestStream,Encoding.UTF8);
AuthStreamWriter.Write(RequestBody);
AuthStreamWriter.Flush;
AuthStreamWriter.Close;
AuthStreamWriter.Dispose;
myResponse := myRequest.GetResponse;
END;
public string GetAuthTokenResponse()
{
string URL = "https://login.microsoftonline.com/xxxxxxxxxxxxxxxxxxxxxxx/oauth2/token";
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(URL);
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.Timeout = 30000;
Stream RequestStream = myRequest.GetRequestStream();
string RequestBody = "client_id=xxxxxxxxxxxxxxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxxxxxxxx&grant_type=client_credentials&redirect_uri=https%3A%2F%2Flocalhost&scope=https%3A%2F%2Fgraph.microsoft.com%2F.default";
StreamWriter AuthStreamWriter = new StreamWriter(RequestStream, Encoding.UTF8);
AuthStreamWriter.Write(RequestBody);
AuthStreamWriter.Flush();
AuthStreamWriter.Close();
AuthStreamWriter.Dispose();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
Stream myResponseStream = myResponse.GetResponseStream();
StreamReader myReader = new StreamReader(myResponseStream, Encoding.UTF8);
return myReader.ReadToEnd();
}
30. November 2022 18:23
1. Dezember 2022 11:28
[TryFunction]
LOCAL PROCEDURE GetAuthTokenResponse@1000000124(URL@1000000007 : Text;ClientID@1000000004 : Text;ClientSecret@1000000005 : Text;Resource@1000000006 : Text;VAR ResponseValue@1000000011 : Text);
VAR
ResponseInStream@1000000000 : InStream;
Request@1000000002 : Text;
TypeHelper@1000000003 : Codeunit 10;
HttpWebRequestMgt@1000000008 : Codeunit 1297;
HttpStatusCode@1000000010 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpStatusCode";
HttpResponseHeaders@1000000009 : DotNet "'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Collections.Specialized.NameValueCollection";
BEGIN
HttpWebRequestMgt.Initialize(URL);
HttpWebRequestMgt.SetMethod('POST');
HttpWebRequestMgt.SetContentType('application/x-www-form-urlencoded');
HttpWebRequestMgt.CreateInstream(ResponseInStream);
Request :=
'grant_type=client_credentials&' +
'client_id=' + TypeHelper.UrlEncode(ClientID) + '&' +
'client_secret=' + TypeHelper.UrlEncode(ClientSecret) + '&' +
'resource=' + TypeHelper.UrlEncode(Resource);
HttpWebRequestMgt.AddBodyAsText(Request);
HttpWebRequestMgt.DisableUI;
HttpWebRequestMgt.SetTraceLogEnabled(TRUE);
IF NOT HttpWebRequestMgt.GetResponse(ResponseInStream,HttpStatusCode,HttpResponseHeaders) THEN
HttpWebRequestMgt.ProcessFaultResponse('');
ResponseInStream.READTEXT(ResponseValue);
END;
[TryFunction] GetWebResponse(VAR HttpWebRequest : DotNet "System.Net.HttpWebRequest";VAR HttpWebResponse : DotNet "System.Net.HttpWebResponse";VAR ResponseInStream : InStream;VAR HttpStatusCode : DotNet "System.Net.HttpStatusCode";VAR ResponseHeaders
IF ProgressDialogEnabled THEN
ProcessingWindow.OPEN(ProcessingWindowMsg);
CLEARLASTERROR;
HttpWebResponse := HttpWebRequest.GetResponse;
HttpWebResponse.GetResponseStream.CopyTo(ResponseInStream);
HttpStatusCode := HttpWebResponse.StatusCode;
ResponseHeaders := HttpWebResponse.Headers;
IF ProgressDialogEnabled THEN
ProcessingWindow.CLOSE;
24. Januar 2023 13:17
LOCAL [TryFunction] GetAuthTokenResponse2(URL : Text;ClientID : Text;ClientSecret : Text;Resource : Text;VAR ResponseValue : Text)
HttpWebRequestMgt.Initialize(URL);
HttpWebRequestMgt.SetMethod('POST');
HttpWebRequestMgt.SetContentType('application/x-www-form-urlencoded');
HttpWebRequestMgt.SetReturnType('application/json');
HttpWebRequestMgt.AddHeader('Authorization', 'Bearer');
HttpWebRequestMgt.AddHeader('cache-control','no-cache');
HttpWebRequestMgt.CreateInstream(ResponseInStream);
Request :=
'grant_type=client_credentials&' +
'client_id=' + TypeHelper.UrlEncode(ClientID) + '&' +
'client_secret=' + TypeHelper.UrlEncode(ClientSecret) + '&' +
'resource=' + TypeHelper.UrlEncode(Resource);
HttpWebRequestMgt.AddBodyAsText(Request);
HttpWebRequestMgt.DisableUI;
HttpWebRequestMgt.SetTraceLogEnabled(TRUE);
IF NOT HttpWebRequestMgt.GetResponse(ResponseInStream,HttpStatusCode,HttpResponseHeaders) THEN
HttpWebRequestMgt.ProcessFaultResponse('');
ResponseInStream.READTEXT(ResponseValue);
24. Januar 2023 13:29
24. Januar 2023 13:45
BastianB hat geschrieben:NAV2017 CU7 - Code funktioniert nicht
NAV2017 CU61 - Code funktioniert
13. April 2023 10:13