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 :
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

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 > 🔒一 Microsoft Dynamics CRM (Archived)

#1
ScottDurow Profile Picture

ScottDurow 2

#2
GJones Profile Picture

GJones 1

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans