Код: Выделить всё
using Microsoft.SharePoint.Client;
using PnP.Framework;
using System;
using System.IO;
namespace AzureADCertAuth
{
class Program
{
static void Main(string[] args)
{
var authManager = new AuthenticationManager("00000000-0000-0000-0000-000000000000", "certpath.pfx", "password", "foo.onmicrosoft.com");
using (var cc = authManager.GetContext("https://foo.sharepoint.com/sites/sitename"))
{
cc.Load(cc.Web, p => p.Title);
cc.ExecuteQuery();
Console.WriteLine(cc.Web.Title);
Microsoft.SharePoint.Client.File file = cc.Web.GetFileByUrl("https://foo.sharepoint.com/sites/sitename/docpath.docx");
ClientResult streamResult = file.OpenBinaryStream();
cc.ExecuteQuery();
using (StreamReader sr = new StreamReader(streamResult.Value))
{
string fileContents = sr.ReadToEnd();
}
}
}
}
}
Я кое-что попробовал вот так
Код: Выделить всё
import com.azure.core.credential.AccessToken;
import com.azure.core.credential.TokenRequestContext;
import com.azure.core.http.HttpClient;
import com.azure.core.http.HttpMethod;
import com.azure.core.http.HttpRequest;
import com.azure.core.http.HttpResponse;
import com.azure.core.http.okhttp.OkHttpAsyncHttpClientBuilder;
import com.azure.identity.ClientCertificateCredential;
import com.azure.identity.ClientCertificateCredentialBuilder;
import java.net.MalformedURLException;
import java.net.URL;
public class SharepointTest {
public static void getAccessTokenCert() {
ClientCertificateCredential credential = new ClientCertificateCredentialBuilder().clientId(
"00000000-0000-0000-0000-000000000000")
.tenantId("11111111-1111-1111-1111-111111111111")
.pfxCertificate("certpath.pfx", "password")
.build();
AccessToken token = credential.getToken(new TokenRequestContext().addScopes("https://foo.sharepoint.com/.default")).block();
String url = "https://foo.sharepoint.com/sites/sitename/docpath.docx";
HttpClient httpClient = new OkHttpAsyncHttpClientBuilder().build();
HttpRequest request = null;
try {
request = new HttpRequest(HttpMethod.GET, new URL(url)).setHeader(
"Authorization", "Bearer " + token.getToken()).setHeader("Accept", "application/json;odata=verbose");
}
catch (MalformedURLException e) {
throw new RuntimeException(e);
}
HttpResponse response = httpClient.send(request).block();
String responseBody = response.getBodyAsString().block();
}
}
throwIfFatal обнаружил фатальное исключение jvm, которое генерируется и регистрируется ниже:: java.lang. NoClassDefFoundError: io/netty/handler/codec/DefaultHeaders$ValueValidator
Есть идеи, что мне нужно сделать по-другому?
Подробнее здесь: https://stackoverflow.com/questions/786 ... on-in-java
Мобильная версия