Hi @Shri-6058 ,
Which site did you connect? Please make sure you are connecting to the admin center site url:
var siteUrl = "https://contoso-admin.sharepoint.com/";
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi I have the working tool for the UPS access and updates. Because I didnt have SharePoint administrator role, I was unable to perform actual property updates. After I received SP administrator role(with MFA - this is our company policy elivated permission should have a MFA configured), The following authCookie (last line) fails staing Miss match with the stored Microsoft account details in the system.. This is because we have MFA configured. code has to be entered. I then did PnP.Framework setup however I am not able to replace the following with the PnP MFA authentication code replacement. Will you advise?
static bool InitializeWebService()
{
try
{
string webServiceExt = "_vti_bin/userprofileservice.asmx";
string adminWebServiceUrl = string.Empty;
//append the web service (ASMX) url onto the admin web site URL
if (_profileSiteUrl.EndsWith("/"))
adminWebServiceUrl = _profileSiteUrl + webServiceExt;
else
adminWebServiceUrl = _profileSiteUrl + "/" + webServiceExt;
LogMessage("Initializing SPO web service " + adminWebServiceUrl, LogLevel.Information);
SecureString securePassword = GetSecurePassword(_sPoAuthPasword);
SharePointOnlineCredentials onlineCred = new SharePointOnlineCredentials(_sPoAuthUserName, securePassword);
// Get the authentication cookie by passing the url of the admin web site
string authCookie = **onlineCred.GetAuthenticationCookie(new Uri(_profileSiteUrl));**
// Setting up the user profile web service
_userProfileService = new UPSvc.UserProfileService();
// assign the correct url to the admin profile web service
_userProfileService.Url = adminWebServiceUrl;
// Assign previously created auth container to admin profile web service
_userProfileService.CookieContainer = authContainer;
// LogMessage("Finished creating service object for SPO Web Service " + adminWebServiceUrl, LogLevel.Information);
return true;
Please let me know. Appreciate any help.
Hi @Shri-6058 ,
Which site did you connect? Please make sure you are connecting to the admin center site url:
var siteUrl = "https://contoso-admin.sharepoint.com/";
Hi @Shri-6058 ,
The SharePointOnlineCredentials
class would not work for tenant with MFA configured.
For your requirement, I would suggest you use CSOM to read or update user profile properties: https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/read-or-update-user-profile-properties-sample-app-for-sharepoint
If an Answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Thank you MichaelHan. I have already overcome the issue with SharePointOnlineCredentioals using PnP framework already. That part is working just fine using below code.
string siteUrl = "https://MyCompany-admin.sharepoint.com";
var authManager = new OfficeDevPnP.Core.AuthenticationManager();
ClientContext ctx = authManager.GetWebLoginClientContext(siteUrl);
Web web = ctx.Web;
ctx.Load(web, w => w.Title);
ctx.ExecuteQuery();
I only have issues now with just updating the properties last function "_userProfileService.ModifyUserPropertyByAccountName(UserName, data);" It says "attempted to perform unauthorized operation". I have sharepoint administrator role, I verified UPS server has full permission to my account still its throwing that error made me stuck.
Please let me know if you have any thoughts.
@MichaelHan-MSFT The link you provided is no longer available. 404.
Unfortunately, this error was from 2014. The following blog is exactly what I am experiencing. As soon as I tried to modify the properties for others, it ends up with unauthorized operations"
http://jopx.blogspot.com/2014/01/automatically-updating-user-profile.html
Anyone experienced this? Please let me know how to overcome updating properties of everyone. I am a SharePoint Administrator, Global administrator still not able to execute "ModifyUserPropertyByAccountName(UserName, data)"