0
votes

I registered an application in Azure Portal and added to it 2 APIs: Azure Active Directory and Microsoft Sharepoint Online with some permissions. I followed the steps from: https://docs.microsoft.com/en-us/outlook/rest/java-tutorial#register-the-app.

The problem is that when I make a request with the Bearer token to the Sharepoint API it gives me an Unauthorized error: 401:

401 Unauthorized x-ms-diagnostics: 3000006;reason="Token contains invalid signature.";category="invalid_client" {"error_description":"Invalid issuer or signature."}

But when I got the access token I have the these scopes:

"token_type":"Bearer","scope":"AllSites.Manage AllSites.Read AllSites.Write Mail.Read MyFiles.Read MyFiles.Write User.Read"

Any idea?

3

3 Answers

1
votes

You can take a look of this project i've made that wraps some common operations that you can perform using the Sharepoint Rest API. Its also a very easy to use API

https://github.com/kikovalle/PLGSharepointRestAPI-java

0
votes

To get SharePoint List data, we can use Office 365 SDKs for Java to achieve it.

Or you can check article below to pass Authentication.

SharePoint REST API Authentication from Java

0
votes

Answer from Francisco Valle does not cover the case when user uses fedaration account. When user is using federation account then whatever tryies the outcome will be the same:

Authentication Failure
<psf:error xmlns:psf="http://schemas.microsoft.com/Passport/SoapServices/SOAPFault">
<psf:value>0x80048821</psf:value>
<psf:internalerror><psf:code>0x80048821</psf:code>
<psf:text>AADSTS50126: Error validating credentials due to invalid username or password

It is because when user uses browser to log in to the SharePoint, there always be redirection to the login page (something like that:

https://adfs.your_domain.com/adfs/ls/?username=your_user_name&wa=wsignin1.0&wtrealm=urn%3afederation%3aMicrosoftOnline&wctx=)

I have not found yet the way how to overcome this redirection in JAVA, and simply generate the token/ or cookie and pass it when using REST API.