Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Unauthorized Operation in SharePoint 2013 WebServices

$
0
0

Hello everyone,

I have an application (Provider-Hosted) that connects to UserProfileServices.asmx on SharePoint Online 2013.

The main functionality is to retrieve and update the user profile properties and privacy. I know that is possible to update the profile properties using CSOM now, but it isn't possible to retrieve and update the privacy of such.

So, the problem is: My application was running fine and from nowhere it start to throw an exception in every method.

My authentication is working fine, the problem is when i call some methods.

Infos:

WebService: https://mysite-admin.sharepoint.com/_vti_bin/UserProfileService.asmx
User: Global Administrator
It is a Provider-Hosted application.
DLL: Microsoft.SharePoint.Client  //  File Version: 15.0.4641.1000 (tried with 16.0.3104.1200 too)

Code to Authenticate (working fine):

var securePassword = new SecureString();
foreach (char c in password)
{
    securePassword.AppendChar(c);
}

var onlineCredentials = new SharePointOnlineCredentials(login, securePassword);

string authCookieValue = OnlineCredentials.GetAuthenticationCookie(_targetAdminSite);
var cookieVal = authCookieValue.TrimStart("SPOIDCRL=".ToCharArray());

_userProfileService.Credentials = System.Net.CredentialCache.DefaultCredentials;

_userProfileService.CookieContainer = new CookieContainer();
_userProfileService.CookieContainer.Add(new Cookie("FedAuth", cookieVal, String.Empty, _targetAdminSite.Authority));

Methods:

var userProfile = _userProfileService.GetUserProfileByName("i:0#.f|membership|" + _targetUser);

var profileSchema = _userProfileService.GetUserProfileSchema();

Exception (when calling a method):

Server was unable to process request. ---> Attempted to perform an unauthorized operation.

Anyone knows what i should do to solve this?

Thanks for your time and efforts!

Reference:

https://msdn.microsoft.com/en-us/library/office/websvcuserprofileservice.aspx



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>