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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Issue with MFA authentication using ADAL Java

(0) ShareShare
ReportReport
Posted on by 17

Hello community.

I have native application, have proper secret key.

Next one - I have JAVA application which properly obtain token, using appId and secret key.

But, when I tried to obtain the data using HTTPClient and token - I always have 401 error.

If need, I present code example below:

String accesToken = result.getAccessToken();

System.out.println(accesToken);

Header odataMaxVersion = new BasicHeader("OData-MaxVersion", "4.0");
Header odataVersion = new BasicHeader("OData-Version", "4.0");
Header headerContentType = new BasicHeader("Content-type", "application/json;IEEE754Compatible=true");

List<Header> headers = new ArrayList<>();

headers.add(odataMaxVersion);
headers.add(odataVersion);
headers.add(headerContentType);

HttpClientContext context = null;
Header headerAuthentication = new BasicHeader("Authorization", "Bearer " + accesToken);
headers.add(headerAuthentication);

HttpClient client = HttpClients.custom().setDefaultHeaders(headers).build();

HttpRequestBase request;
HttpResponse response = null;

String requestURLString = RESOURCE + "/api/data/v9.0/EntityDefinitions(LogicalName='invoice')/Attributes?$filter=IsValidForRead%20eq%20true";
request = new HttpGet(requestURLString);

response = client.execute(request, context);
int responseCode = response.getStatusLine().getStatusCode();

Finally, responseCode is 401.
May be I'm an idiot

*This post is locked for comments

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

    Hi,

    Try checking request with Postman once, might help you track exact issue.

    Regards,

    Ketan

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…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans