我们在Sharepoint上使用多因素身份验证。我们正在尝试从共享点下载一些文档以在我们的应用程序中进行操作。我尝试使用“传统”方法访问共享点,并尝试通过我们的Azure AD。这两种方法均不允许我们访问共享点-我们的权限被拒绝
任何帮助将不胜感激
这是我已经尝试过的方法-通过广告
string clientId = "xxx";
string clientSecret = "yyy";
string tenant = "zzz";
AuthenticationResult result = null;
var data = AzureAdOptions.Settings.Authority;
AuthenticationContext authContext = new
AuthenticationContext(AzureAdOptions.Settings.Authority);
ClientCredential credential = new
ClientCredential(AzureAdOptions.Settings.ClientId,
AzureAdOptions.Settings.ClientSecret);
result = await
authContext.AcquireTokenAsync(AzureAdOptions.Settings.PreceptWebApiResourceId, credential);
HttpClient client = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);
request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", result.AccessToken);
HttpResponseMessage response = await client.SendAsync(request);
然后是更“传统的方式”
WebRequest request = WebRequest.Create("https://my.sharepoint.com:/sites/files/");
string userName = "mylogon";
string password = "@!";
var securePassword = new SecureString();
foreach (char c in password)
{
securePassword.AppendChar(c);
}
request.Credentials = new NetworkCredential(userName, securePassword);
String encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(userName + ":" + password));
request.Headers.Add("Authorization", "Basic " + encoded);
WebResponse response = request.GetResponse();
答案 0 :(得分:0)
替换下面的代码行
5.0
使用
4.01
request.Credentials = new NetworkCredential(userName, securePassword);
引用:CSOM.MFA.cs