Posted on 29/10/2025 21:08:08
You might also be able to create a custom endpoint auth for Dynamicweb that understands Sap B1:
This is our endpoint auth for basic authentication - one for B1 would work similar.
using System;
using System.Net;
using System.Net.Http;
using Dynamicweb.Core;
using Dynamicweb.Extensibility.AddIns;
using Dynamicweb.Security.SystemTools;
namespace Dynamicweb.DataIntegration.EndpointManagement.AuthenticationAddIns;
[AddInName("Basic")]
[AddInLabel("Basic")]
[AddInDescription("Basic")]
public class BasicEndpointAuthenticationAddIn : BaseEndpointAuthenticationAddIn
{
[AddInParameter("Username")]
[AddInParameterEditor(typeof(Extensibility.Editors.TextParameterEditor), "")]
public string? UserName { get; set; }
[EncryptParameter]
[SensitiveData]
[AddInParameter("Password")]
[AddInParameterEditor(typeof(Extensibility.Editors.TextParameterEditor), "password=true")]
public string? Password { get; set; }
[Obsolete("Do not use.")]
public override EndpointAuthenticationType AuthenticationType => EndpointAuthenticationType.Basic;
public override string? ValidateParameters()
{
return null;
}
public override void PrepareClient(Uri uri, HttpClient client, HttpClientHandler clientHandler, Endpoint endpoint)
{
Ensure.NotNull(clientHandler, "clientHandler");
NetworkCredential credential = new NetworkCredential
{
UserName = UserName,
Password = !string.IsNullOrEmpty(Password) && (endpoint?.Authentication?.Encrypted ?? false) ? Crypto.Decrypt(Password) : Password,
};
CredentialCache credentialCache = new CredentialCache
{
{ uri, "Basic", credential }
};
clientHandler.Credentials = credentialCache;
}
}
It would look something like this for Sap Business one (Totally untested)...
[AddInName("SAP Business One Service Layer")]
[AddInLabel("SAP B1 Service Layer")]
[AddInDescription("Authenticates using SAP B1 Service Layer Login endpoint")]
public class SapB1ServiceLayerAuthenticationAddIn : BaseEndpointAuthenticationAddIn
{
[AddInParameter("Company DB")]
[AddInParameterEditor(typeof(Extensibility.Editors.TextParameterEditor), "")]
public string? CompanyDB { get; set; }
[AddInParameter("Username")]
[AddInParameterEditor(typeof(Extensibility.Editors.TextParameterEditor), "")]
public string? UserName { get; set; }
[EncryptParameter]
[SensitiveData]
[AddInParameter("Password")]
[AddInParameterEditor(typeof(Extensibility.Editors.TextParameterEditor), "password=true")]
public string? Password { get; set; }
[Obsolete("Do not use.")]
public override EndpointAuthenticationType AuthenticationType => EndpointAuthenticationType.None;
public override string? ValidateParameters()
=> string.IsNullOrEmpty(UserName) || string.IsNullOrEmpty(Password) || string.IsNullOrEmpty(CompanyDB)
? "All fields are required." : null;
public override void PrepareClient(Uri uri, HttpClient client, HttpClientHandler handler, Endpoint endpoint)
{
var loginUri = new Uri(uri, "/b1s/v2/Login");
var body = new { CompanyDB, UserName, Password };
var loginJson = System.Text.Json.JsonSerializer.Serialize(body);
var request = new HttpRequestMessage(HttpMethod.Post, loginUri)
{
Content = new StringContent(loginJson, System.Text.Encoding.UTF8, "application/json")
};
var response = client.Send(request);
if (!response.IsSuccessStatusCode)
throw new Exception($"SAP B1 login failed: {response.StatusCode}");
// Capture cookies from login response
if (response.Headers.TryGetValues("Set-Cookie", out var cookies))
{
var cookieContainer = new CookieContainer();
foreach (var cookie in cookies)
cookieContainer.SetCookies(uri, cookie);
handler.CookieContainer = cookieContainer;
}
}
}