Skip to main content

Notifications

Announcements

No record found.

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

  • raelhefn Profile Picture
    on at
    RE: 401 Unauthorized response when Using Oauth with Onprem Install

    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

  • BG@Dynamics Profile Picture
    60 on at
    RE: 401 Unauthorized response when Using Oauth with Onprem Install

    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

  • Suggested answer
    raelhefn Profile Picture
    on at
    RE: 401 Unauthorized response when Using Oauth with Onprem Install

    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

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

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

#1
YUN ZHU Profile Picture

YUN ZHU 628 Super User 2025 Season 1

#2
Mansi Soni Profile Picture

Mansi Soni 495

#3
Sohail Ahmed Profile Picture

Sohail Ahmed 434

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans