Calling /_vti_bin/homeapi.ashx/sites/recent using SharePointOnlineCredentials

Pablo Glomby 186 Reputation points
2021-01-11T15:04:36.89+00:00

Hi!
I am trying to call /_vti_bin/homeapi.ashx/sites/recent to get the recent sites for a given user.
The way I login is by using SharePointOnlineCredentials (username + pwd)
The code I use is:
using (var client = new WebClient())
{
client.Credentials = creds;
client.Headers.Add("X-RequestDigest", dig.DigestValue);
client.Headers.Add("X-FORMS_BASED_AUTH_ACCEPTED", "f");
client.Headers.Add(HttpRequestHeader.ContentType, "application/json;odata=verbose");
client.Headers.Add(HttpRequestHeader.Accept, "application/json;odata=verbose");
client.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0");
client.Headers.Add("SPHome-ClientType", "SharePointIOS");
var endpointUri = new Uri(szRequestURL);
byte [] answer= client.DownloadData(szRequestURL);
}

But I get an error 401. If I login using MSAL or ADAL (so I register an app) then it works (here I don't use SharePointOnlineCredentials)... but in some customers I cannot register an app.

Is it possible to call that REST API using SharePointOnlineCredentials?

Thanks

Microsoft 365 and Office | SharePoint | For business | Windows
Microsoft 365 and Office | SharePoint Server | Development
Microsoft Security | Microsoft Entra | Microsoft Entra ID
Microsoft Security | Microsoft Graph

1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.

    1 deleted comment

    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.