web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Business Central forum

How do I find and use certificates in AL code?

(0) ShareShare
ReportReport
Posted on by 20

Hi all

How do I find and use certificates in AL code for Business Central Cloud?

In my AL code Extension for Business Central Cloud, I'm trying to communicate with a third-party web service that requires a mutual authentication via TSL.

Here is what I have:

procedure InvokeWebOp(ContentText: Text)
var
  Content: HttpContent;
  Headers: HttpHeaders;
  Client: HttpClient;
  Response: HttpResponseMessage;
  ErrorLabel001: Label 'The call to the web service failed.';
  TempText: Text;
  Cert: Text;
begin
  Content.WriteFrom(ContentText);
  Content.GetHeaders(Headers);
  Headers.Remove('Content-Type');
  Headers.Add('Content-Type', 'application/json');

  // cert = ???
  Client.AddCertificate(cert);
  if not Client.Get('https://[service]/api/Values', Response) then
    Error(ErrorLabel001);

  // Check if successful
  if not Response.IsSuccessStatusCode then begin
    Message('Call failed' + Response.ReasonPhrase);
  end
  else begin
    Response.Content.ReadAs(TempText);
    Message('Call to Values returned: ' + TempText);
  end;
end;

I'm not sure if I'm on the right track but so far I found that I can upload my certificate using the Business Central Web Client - Certificates page and set the access - user or company. However I can't find out how to lookup and use the certificate.

Any help is much appreciated.

Thorbjorn

Categories:
I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    The certificate is installed on client side, so you cannot use it on SaaS. In order to use it, you need to upload the Base64 of this certificate online (for example on the Isolated Storage). Then you can use:

    Client.AddCertificate(YourBase64CertificateString);

  • TSax Profile Picture
    5 on at

    Hi Thorbjorn

    I'm about to create an integration that requires sertificate authentication. Did you manage to resolve your issue?

    Could I stream the sertificate to a blob value in the database and use this in the httpClient? Or do I need to create a blob storage as Stefano suggested?

    Best Regards

    Thomas

  • thorbjorn Profile Picture
    20 on at

    Hi Thomas

    We had issues with using Isolated Storage in the Saas setup.  Many of the operations were scoped for On-Prem only so we soon changed our approach.  In our solution we use Azure Key Vault to store the certificates and other secrets and a WebApp to perform the operations we need.  Azure Functions may also have been a good option.

    Hope this helps

    Thorbjorn

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Business Central

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans