SPO Tenant authientication with MFA configured account CSOM application

Shri-6058 326 Reputation points
2021-09-23T20:50:53.79+00:00

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.

SharePoint
SharePoint
A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.
9,682 questions
SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,575 questions
SharePoint Server Management
SharePoint Server Management
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Management: The act or process of organizing, handling, directing or controlling something.
2,810 questions
{count} votes

12 answers

Sort by: Most helpful
  1. Shri-6058 326 Reputation points
    2021-09-24T22:59:57.757+00:00

    I tried with PeopleManager but it throws error again as shown below:

    User Error: Exception trying to update profile properties for user i:0#.f|membership|xyzs@Piepel .com This operation requires you to be managing your own data or have administrator privileges.

    I'm and have a SharePoint Administrator role but it doesnt allow me to update for others. What could be an issue?

    0 comments No comments

  2. Shri-6058 326 Reputation points
    2021-09-24T23:43:39.86+00:00

    This is unbeleivable. There must be a bug. I am a global administrator and its throwing error(however it works for myself but not for others):
    135194-image.png

    0 comments No comments

  3. Shri-6058 326 Reputation points
    2021-09-25T06:55:39.537+00:00

    I saw another discussion https://learn.microsoft.com/en-us/answers/questions/456195/issue-updating-user-property.html and it seems the properties cant be updated using CSOM. Do we have any update?

    I am still able to upate my own properties but not other users. I really want this application to update by any mean and dont want to write another add in.

    string updatedValue = "This is test UPS About Me";
    peopleManager.SetSingleValueProfileProperty(UserName, "AboutMe", updatedValue);
    peopleManager.SetSingleValueProfileProperty(UserName, "PictureURL", PropertyValue[0]);
    // peopleManager.SetSingleValueProfileProperty(UserName, "SPS-PicturePlaceholderState", PropertyValue[1]);
    spContext.ExecuteQuery();

    Please advise.

    0 comments No comments

  4. Shri-6058 326 Reputation points
    2021-09-29T17:28:18.84+00:00

    Any advise? Please help.

    0 comments No comments

  5. Shri-6058 326 Reputation points
    2021-09-30T18:32:20.37+00:00

    I am connecting to admin site. I have a SharePoint administrator role. All working fine for myself updating properties values however for others, its throwing error as shown above thread.

    0 comments No comments