0
votes

I am trying to connect from Java to the Sharepoint Online REST API.

I previously used a SharepointOnline ADD-IN registered directly in the Sharepoint system that has permissions to all the site collections (FullControl). I got the token with the app credentials from the url: https://accounts.accesscontrol.windows.net//tokens/OAuth/2 I can make requests to the Sharepoint REST API directly

Now I have to switch to an Azure registered app. The code is written in Java and I use the Azure sdk-com.microsoft.azure (artifactId-azure). I can successfully retrieve a token, but this is not valid for later requests to the Sharepoint REST API.

I get this error: 'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException' was thrown."

Is there any possibility to get a valid token for Sharepoint REST API requests?

2

2 Answers

0
votes

Yes this is possible. Check out the below document:

https://docs.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azuread

When using SharePoint Online you can define applications in Azure AD and these applications can be granted permissions to SharePoint, but also to all the other services in Office 365. This model is the preferred model in case you’re using SharePoint Online, if you’re using SharePoint on-premises you have to use the SharePoint Only model via based Azure ACS as described in here.

Hope this helps!

0
votes

You can take a look of this project i've develop (and i'm currently working on it on my free time) where you have a working implementation of a java API to communicate with sharepoint rest api v1 and perfom common operations (rest api is still not fully covered but has most common operations and also provides a starting point with working examples). You can take a look of it at

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