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

Notifications

Announcements

Community site session details

Community site session details

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

401 Unauthorized response when Using Oauth with Onprem Install

(0) ShareShare
ReportReport
Posted on by 60

I'm getting an http 401 "unauthorized" response from the web api on version 18.0.22893.23773.  This is a on-prem installation.  Is it possible to do the Oauth authentication with an On-prem or do you have to do Windows or user/password?

I have set up an app registration in AAD and set permissions on it, assigned a secret key, etc.  I am able to get a token from AAD but when I try to use that token in Business Central, I keep getting the 401.  

Can anybody shed some light on this?

Here are the configs for the system.  I tried changing the Credential Type from Windows to AccessControlService and using a certificate to get a thumbprint value but, that fell short.

pastedimage1629555466909v1.png

pastedimage1629555484699v2.png

I have the same question (0)
  • Suggested answer
    raelhefn Profile Picture
    on at

    Hi,

    With authentication methods other than Azure AD, like Windows or NavUserPassword, the credentials that users provide are persisted by application and used for as long as they're valid in Business Central. However, this is more complicated for OAuth, because the security tokens that are used for authentication have a limited lifetime.

    Maybe these links can be useful In this issue:

    docs.microsoft.com/.../authenticate-web-services-using-oauth

    docs.microsoft.com/.../devenv-develop-connect-apps

    www.msnjournals.com/.../generic-oauth2-library-for-business-central

  • BG@Dynamics Profile Picture
    60 on at

    Thanks for the input.  I don't think I'm in any danger of the AAD token expiring since I'm trying to use it in the code milliseconds after getting it from AAD.  Here's the code:

    pastedimage1629688257041v1.png

  • raelhefn Profile Picture
    on at

    401 Unauthorized error: Is your token valid?

    If you consistently get 401 unauthorized errors, verify that you have a valid access token. If you have not already done so, create a basic Azure Active Directory (Azure AD) application and a service principal as described in Use portal to create an Azure Active Directory application and service principal that can access resources. Then, use the application or a simple HTTP POST request to verify your access. You will include the Tenant ID, Application ID, Object ID, and the secret key to obtain the access token.

    docs.microsoft.com/.../cloud-partner-portal-api-troubleshooting-authentication-errors

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

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

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,170 Super User 2026 Season 1

#2
Dhiren Nagar Profile Picture

Dhiren Nagar 1,283 Super User 2026 Season 1

#3
YUN ZHU Profile Picture

YUN ZHU 1,104 Super User 2026 Season 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans