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

  • Suggested answer
    NODAL Profile Picture
    860 on at
    RE: Issue with MFA authentication using ADAL Java

    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

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

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans