It's so simple:
OAuth protocol for authentication
list files from documentLibrary and checkout a file from the list
written in javascript
I've been struggling with this for few days with no such luck so far.
CHECKOUT OPTION 1 - Graph API:
https://docs.microsoft.com/en-us/onedrive/developer/rest-api/api/driveitem_checkout
Even though it's OneDrive API, it's should be running with SharePoint doc.libraries as well - RESt APIs
section: "The REST API is shared between OneDrive, OneDrive for Business, SharePoint document libraries, and Office Groups, to allow... "
The result? check it out here: Sharepoint `Unsupported segment type` when checkin/chekout file
Good news the OAuth works like a charm - I got the client ID from https://apps.dev.microsoft.com/, authentication endpoint:
https://login.microsoftonline.com/common/oauth2/v2.0/authorize
https://login.microsoftonline.com/common/oauth2/v2.0/token
CHECKOUT OPTION 2 - Sharepoint Add-in
https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-folders-and-files-with-rest
url: http://site url/_api/web/GetFileByServerRelativeUrl('/Folder Name/file name')/CheckOut(),
method: POST
headers:
Authorization: "Bearer " + accessToken
X-RequestDigest: form digest value
This one works perfectly, but in this case, OAuth is the issue ...
this link is promising: https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/authorization-code-oauth-flow-for-sharepoint-add-ins
however, in the process, there is the Microsoft Azure Access Control Service (ACS) involved, which is (according to this link https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-acs-migration) about to switch off.
Solution seems to be is a switch to Azure application (https://portal.azure.com -> Azure Active Directory -> App registrations). Anyway, access token using these settings is not compatible with access token required for the Sharepoint API, e.g.:
https://mindjet2.sharepoint.com/_api/contextinfo
throws exception
'Microsoft.IdentityModel.Tokens.AudienceUriValidationFailedException'
What I'm doing wrong with the graph api? What is the right way to authenticate the Sharepoint API using OAuth?