0
votes

I understand how to access the Sharepoint REST API using interactive authentication, i.e. having a user at the computer type a username/password into a webapp. Is there a way to let a commandline app access the API? e.g. connect and query a Sharepoint list without user intervention?

I've registered a native client in the tenant and have an AppId (no app secret) but all API calls return 401 Unauthorized. I've also tried accessing via the Graph API but get 403 Forbidden. These are both using the access_token from the initial client_credentials flow of a tenant registered web app, which I would expected to have worked.

It doesn't appear to be possible to get an access_token using only an AppId as the flow requires a client secret.

This says:

This type of permission requires administrator consent and is also not available for native client applications

which doesn't appear to make sense as it requires administrator permissions for something that can't be done. If native clients can't access APIs it's not clear what they're for. Perhaps the above refers to web apps rather than native clients, i.e. an Admin can allow a web app to connect using an access_token without a user context.

2

2 Answers

0
votes

Regarding getting the token from SharePoint (using the SharePoint REST API) please see my answer to this post: https://stackoverflow.com/a/52582017/6445723

The mechanism is basically the same, you do the POST request described there from your application and get the answer in the FormDigestValue property. Use this value henceforth in ALL your API calls by placing it into the X-RequestDigest HTTP header.

AFAIK there is no difference in authentication mechanisms for native clients or other web applications. Some libraries like the SharePoint PnPJS can abstract out the REST call above, but they do pretty much the same thing.

-3
votes

You need to enable Basic Authentication credentials are sent in clear text in Authentication Providers. Goto Central Admin>> Security>>Security Authentication providers>> In Right side dropdown select the Application and click on default

Tick Basic Authentication in Claims Authentication Types