/// <summary> /// No SPO client API for administering user profiles, so need to use traditional ASMX service for user profile work. This function initiates the /// web service end point, and authenticates using Office 365 auth ticket. Use SharePointOnlineCredentials to assist with this auth. /// </summary> /// <returns></returns> 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); //get secure password from clear text password SecureString securePassword = GetSecurePassword(_sPoAuthPasword); //get credentials from SP Client API, used later to extract auth cookie, so can replay to web services 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)); // Create a CookieContainer to authenticate against the web service CookieContainer authContainer = new CookieContainer(); // Put the authenticationCookie string in the container authContainer.SetCookies(new Uri(_profileSiteUrl), authCookie); // 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); } catch (Exception ex) { LogMessage("Error initiating connection to profile web service in SPO " + ex.Message, LogLevel.Error); return(false); } }
public PictureUploader(string profileSiteUrl, string mySiteUrl, string sPoAuthUsername, string sPoAuthPasword, string profilePhotoPath) { _clientContext = GetClientContext(mySiteUrl, sPoAuthUsername, sPoAuthPasword); _userProfileService = GetUserProfileService(profileSiteUrl, sPoAuthUsername, sPoAuthPasword); _profilePhotoPath = string.Concat(profilePhotoPath.TrimEnd('/'), "/{0}_{1}Thumb.jpg"); }