SharePointOnlineCredentials не может найти учетную запись и - PullRequest
0 голосов
/ 14 апреля 2020

Я пытаюсь подключиться к точке доступа моей компании, но учетные данные, которые я использую (мой адрес электронной почты и пароль), не распознаются, и в строке ExecuteQuery выдается ошибка. Кроме того, когда я пытаюсь получить файлы, используя относительные пути или URL-пути, каждое отдельное свойство выдает Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException.

 private static readonly HttpClient client = new HttpClient();

[FunctionName("SendFiles")]
public static async Task<HttpResponseMessage> Run(
    [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequestMessage req,
    ILogger log)
{

    ClientContext context = new ClientContext("https://abc.sharepoint.com/sites/a-b");
    SecureString secureString = new SecureString();
    foreach(char c in "dummypass")
    {
        secureString.AppendChar(c);
    }
    context.Credentials = new SharePointOnlineCredentials("a.b@faktion.com", secureString);
    Web site = context.Web;

   string jsonInput = req.Content.ReadAsStringAsync().Result;
   SendFilesInput input = JsonConvert.DeserializeObject<SendFilesInput>(jsonInput);

   string url = "https://a.b.com/gql/api/organisations/" + input.OrganisationId + "/projects/" + input.ProjectId + "/process";
   string response = null;
   bool succesfullRequest = false;
   MultipartFormDataContent formdata = new MultipartFormDataContent();
   try
   {
        foreach (var filePath in input.Files)
        {
            // create filestream content
            var fileurl = "https://abc.sharepoint.com/sites/a-b" + "/" + filePath;


            Microsoft.SharePoint.Client.File temp = site.GetFileByServerRelativeUrl(filePath);
            Microsoft.SharePoint.Client.File temp2 = site.GetFileByUrl(fileurl);
            ClientResult<Stream> crstream = temp.OpenBinaryStream();
            ClientResult<Stream> crstream2 = temp2.OpenBinaryStream();
            context.Load(temp);
            context.Load(temp2);
            context.ExecuteQuery();

            var tempfile = Path.GetTempFileName();
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            if (crstream.Value != null)
            {
                crstream.Value.CopyTo(fs);
            }
            HttpContent content = new StreamContent(fs);
            string name = GetFileName(filePath);
            content.Headers.Add("Content-Type", GetFileType(name));
            formdata.Add(content, "files", name);
            System.IO.File.Decrypt(tempfile);
        }
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", input.BearerToken);
        // send content to the backend and parse result
        var resultPost = client.PostAsync(url, formdata).Result;
        response = resultPost.Content.ReadAsStringAsync().Result;
        succesfullRequest = resultPost.IsSuccessStatusCode;
    }
    // I absolutely want to catch every exception and pass these along to the workflow
    catch (Exception ex)
    {
        req.CreateErrorResponse(HttpStatusCode.BadRequest, ex);
    }
    // if something went wrong in the backend, throw an error
    if (!succesfullRequest)
    {
         req.CreateErrorResponse(HttpStatusCode.BadRequest, "Something went wrong during the upload process");
    }
[...] // rest is not important

Ошибка:

Имя входа или пароль не совпадает с паролем в системе учетных записей Microsoft.

Console Output

...