Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Business Central forum

Get the Access Token with manual requests

(0) ShareShare
ReportReport
Posted on by 60

Hi, 

My goal is to receive the Access Token programmatically, for this i decided at first to do this through Postman.

I'd like to say that my Business Central app is configured with AAD, so I have all the necessary credentials for future requests:

1) Directory (tenant) ID
2) Application (client) ID
3) Client secret

At first I'm trying to make Authorization Request to receive Authorization code. As it is written in official  Oauth 2.0 documentation, I should use the authorization endpoint URI.

In my case it looks like : https://login.windows.net/{{tenantID}}/oauth2/authorize?response_type=code&client_id={{client_id}}&redirect_uri=https://businesscentral.dynamics.com/{{tenantID}}/Sandbox --- GET

This request successfully returns me an authorization code, which is necessary to request an Access token.

My next step is Access Token Request

It contains of:

grant_type
         REQUIRED.  Value MUST be set to "authorization_code".
   code
         REQUIRED.  The authorization code received from the
         authorization server.
   redirect_uri
         REQUIRED, if the "redirect_uri" parameter was included in the
         authorization request, and their
         values MUST be identical.
   client_id
         REQUIRED, if the client is not authenticating with the
         authorization server

Access Token endpoint looks like:
login.microsoftonline.com/.../token --- POST
All necessary parameters are set in the body. But, without the client_secret it returns me:
"AADSTS7000218: The request body must contain the following parameter: 'client_assertion' or 'client_secret'."

If I set the client secret from AAD it returns me "AADSTS7000215: Invalid client secret is provided"


This client secret works if i use Postman Oauth 2.0 authentication to receive access token, so the reason is not in credentials but in my actions.

Any ideas? Thanks in advance!
Categories:
  • Suggested answer
    Nishant Rana Profile Picture
    11,323 Microsoft Employee on at
    RE: Get the Access Token with manual requests

    This should help

    nishantrana.me/.../

  • alex_li Profile Picture
    60 on at
    RE: Get the Access Token with manual requests

    Oauth documentation:

    https://tools.ietf.org/html/draft-ietf-oauth-v2-31#section-4 (My steps start from 4. Obtaining Authorization)

    The goal is to obtain access token for further actions with Business Central programmatically.

    If I use this postman feature everything is good, but I need to do it manually.

    pastedimage1567760011610v1.png
  • Community Member Profile Picture
    on at
    RE: Get the Access Token with manual requests

    Hi Alex,

    Which documentation are you using for the Access Token request? I'm not quite sure I understand what you are trying to do, but it seems your request is valid, so it could be wrong encoding, maybe missing Url encoding. Also, could be missing Base64String encoding. Postman will do things for you that need to be explicitly programmed in code.

    Tero  

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 forum

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans