Skip to main content

Notifications

Announcements

No record found.

Business Central forum

How do I find and use certificates in AL code?

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:
  • thorbjorn Profile Picture
    thorbjorn 20 on at
    RE: How do I find and use certificates in AL code?

    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

  • TSax Profile Picture
    TSax 5 on at
    RE: How do I find and use certificates in AL code?

    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

  • Suggested answer
    Stefano Demiliani Profile Picture
    Stefano Demiliani 37,162 Most Valuable Professional on at
    RE: How do I find and use certificates in AL code?

    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);

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

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans