我正在编写一个称为Sharepoint-online API的集成,我的集成不是一个has应用程序,必须在没有用户在场的情况下工作。
据我所知,我需要两个设置步骤: 1.用户必须登录Azure并设置应用程序并获取客户端ID。2.我必须使用客户端ID、用户名和密码调用服务,然后才能获得访问令牌、刷新令牌和ID令牌。
两个设置步骤完成后,我可以使用访问令牌调用服务,但有时会过期,我需要使用刷新令牌来获得一个新的令牌。
第二步对我来说很奇怪。为什么没有用户界面,用户可以登录并获得Access和ID令牌?是否有人建立了一个公用事业网站,只是这样做,或我误解了什么?
谢谢罗伯特
发布于 2017-06-01 12:26:16
推荐的用于服务和守护进程应用程序的流是客户端凭据流(在该流程中,不涉及;客户端ID和客户端秘密用于获取最终过期的访问令牌,然后需要使用相同的客户端ID和机密获取新的访问令牌)。在SharePoint Online的情况下,为此场景提供了两个选项:
Program.cs
static void Main(string[] args)
{
Uri siteUri = new Uri("https://tenant.sharepoint.com/teams/test");
//Get the realm for the URL
string realm = TokenHelper.GetRealmFromTargetUrl(siteUri);
//Get the access token for the URL.
// Requires this app to be registered with the tenant
string accessToken = TokenHelper.GetAppOnlyAccessToken(
TokenHelper.SharePointPrincipal,
siteUri.Authority, realm).AccessToken;
HttpWebRequest endpointRequest =
(HttpWebRequest)HttpWebRequest.Create(
"https://tenant.sharepoint.com/teams/test/_api/web/lists/GetByTitle('Documents')/items");
endpointRequest.Method = "GET";
endpointRequest.Accept = "application/json;odata=verbose";
endpointRequest.Headers.Add("Authorization", "Bearer " + accessToken);
HttpWebResponse endpointResponse =
(HttpWebResponse)endpointRequest.GetResponse();
}
}app.config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<appSettings>
<add key="ClientId" value="65e674ca-3827-4134-852b-1196ff935e08"/>
<add key="ClientSecret" value="xxxxxxx"/>
</appSettings>
</configuration>https://stackoverflow.com/questions/44302399
复制相似问题