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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Small and medium business | Business Central, N...
Suggested Answer

Authenticate in external service from the BC extension

(2) ShareShare
ReportReport
Posted on by 40
I'm working on a Business Central extension, and its job is to help users provision their BC company in an external service. The desired flow looks like:
 
1) User installs an extension and opens a setup wizard
2) The user clicks the "Login" button and is redirected to an external authentication server (not Entra), where they log in using their credentials (Microsoft, Google, etc.) for the external web service.
3) Extension got back its access token and performs an API call to the external web service to provision the BC company there.
 
How to implement such a flow? I saw only tutorials about how to get access from an external service to Business Central, but not vice versa.
I have the same question (0)
  • Suggested answer
    Sohail Ahmed Profile Picture
    11,173 Super User 2026 Season 1 on at

    To implement this external authentication flow from a Business Central extension, you'll need to handle external OAuth2 authentication manually via AL code and JavaScript interop. Here's a high-level breakdown:

     
     

    🔐 Recommended Flow (OAuth2 Authorization Code Grant with PKCE)

     

    1.  

      Launch external login via JavaScript

       

      •  

        Use ControlAddIn (with JavaScript) or OpenUrl to redirect the user to the external service's auth URL (e.g. https://external.com/auth?client_id=...).


      •  

        Make sure it includes the redirect_uri to return back to your extension or a proxy web service you control.



      •  

    2.  

      Handle redirect and receive token

       

      •  

        The redirect URI should be hosted externally (Azure Function or web API) and receive the authorization code.


      •  

        Exchange the authorization code for an access token using the external service's token endpoint (from your backend or through BC using HttpClient).



      •  

    3.  

      Call External API

       

      •  

        Use HttpClient in AL to send requests to the external API with the access token received.


      •  

        Store the token securely using the Isolated Storage or encrypt before saving in BC.



      •  


    4.  
     
     

    💡 Key AL Components

     

    •  

      HttpClient and HttpContent for API communication.


    •  

      ControlAddIn for login redirection (or use OpenUrl).


    •  

      Page Extensions or custom Setup Wizard to host the login action.



    •  
     
     

    🔁 Summary

     

    •  

      You cannot complete OAuth2 fully inside AL only due to interactive login. You must use a browser-based redirection.


    •  

      Use a secure backend service to handle sensitive parts like the token exchange, if possible.


    •  

      BC does not natively handle external auth redirects, so browser-to-backend, then backend-to-BC is the safe route.



    •  
     
     

    ✅ Mark below checkbox to make this answer Verified if it helps you.

  • Anton Kheistver Profile Picture
    40 on at
     
    Thanks! But how to pass the exchanged token back to BC?
  • Suggested answer
    Sohail Ahmed Profile Picture
    11,173 Super User 2026 Season 1 on at

    You're welcome! 😊

     

    Once the user is authenticated on the external service and the token is obtained (usually via a redirect with a query parameter), you can pass the token back to Business Central using one of these common approaches:

     

    ✅ Option 1: Redirect to a Public Webhook / Azure Function

    • Create a public-facing Azure Function or Web API endpoint.
    • After authentication, redirect the user to that endpoint with the token in the query.
    • From there, call a Business Central custom API to store the token in a setup table (use OAuth for secure access).

    ✅ Option 2: Custom Page + JavaScript Control Add-in (Advanced)

    • Use a JavaScript control add-in hosted on a page in BC.
    • On login, open the auth URL in a pop-up.
    • After authentication, the control add-in can capture the token from the redirect and send it back to BC using a callback method.

    ✅ Option 3: Manual Token Paste (Simpler)

    • After login, redirect to a static page that displays the token to the user.
    • The user manually pastes the token back into a field in your extension setup page.
     

     

     

    ✅ Mark below checkbox to make this answer Verified if it helps you.

  • Anton Kheistver Profile Picture
    40 on at
    any code examples? 
  • Sohail Ahmed Profile Picture
    11,173 Super User 2026 Season 1 on at
    @Anton Kheistver Will share in my free time
  • Suggested answer
    Ramesh Kumar Profile Picture
    7,549 Super User 2026 Season 1 on at
    Any reason why your following this process?
     

    Use Token in Your AL Code : Now you can use 

    HttpClient in your extension: HttpClient.Get('https://external-service.com/api/provision?company=' + CompanyName, HttpResponseMessage);

     
    Thanks
    Ramesh
     
    If this was helpful, please check the "Does this answer your question?" box and mark it as verified.
  • Suggested answer
    Khushbu Rajvi. Profile Picture
    22,346 Super User 2026 Season 1 on at

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 1,947 Super User 2026 Season 1

#2
YUN ZHU Profile Picture

YUN ZHU 995 Super User 2026 Season 1

#3
Teagen Boll Profile Picture

Teagen Boll 596 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans