在 SharePoint 2016 中获取仅应用程序访问令牌

发布于 2025-01-17 14:01:39 字数 1654 浏览 3 评论 0 原文

我正在尝试运行AC#控制台应用程序,这是定期从XML同步的全局TERSTORE。这将被认为是一个定时像,它将在Windows调度程序中运行。 目标是SharePoint 2016环境。

由于我们不想为此目的使用服务帐户,因此我们希望基于此 https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-apponly-azureacs

/ security 正确地,同样的方法也应适用于本地环境?

SharePoint应用程序仅是较旧的,但仍然非常相关地设置App-principals。该型号适用于SharePoint在线和SharePoint 2013/2016/2019本机上,非常适合为您的申请做好从SharePoint在本地迁移到SharePoint的应用程序。

我可以使用以下代码成功地将整个控制台应用程序与我们的SharePoint Online Dev-Tenant运行。

但是现在,当我尝试在SharePoint 2016环境中运行此功能时,它一直在失败。

我做的与在线SharePoint的同一件事。我创建了一个应用程序(通过appnewreg.aspx),授予相同的权限(通过appinv.aspx),并相应地交换了SiteUrl,ClientId和Clientsecret。

            string siteUrl = "MySiteUrl";
            string clientId = "ClientId";
            string clientSecret = "ClientSecret";
            using (var clientContext = new AuthenticationManager().GetACSAppOnlyContext(siteUrl, clientId, clientSecret))
            {
                var web = clientContext.Web;
                clientContext.Load(web, w => w.Title);
                clientContext.ExecuteQuery();
                Console.WriteLine(web.Title);
            };

但是我无法运行控制台应用程序。 收到以下错误:

远程服务器返回错误:(400)不良请求。 - {“错误”:“ Invalid_request”,“ error_description”:“ AADSTS90002:租户'8A450D28-F099-4C54-BCB9-DDCED3A8C499'找不到。检查以确保您拥有正确的租户并签署了正确的云。请与您的订阅管理员联系,如果租户没有主动订阅,这可能会发生。\

从我的理解来看,我不需要一个提供商托管的应用程序,我不需要高信任还是低信任?

I am trying to get a c# console application running, that is synchronizing the global termstore from an xml on a regular basis. This is gonna be supposed a timerjob, that will run in the windows schedueler.
The target ist a SharePoint 2016 environment.

Since we dont wanna use a service account for that purpose, we want to use the app-only mode based on this https://learn.microsoft.com/en-us/sharepoint/dev/solution-guidance/security-apponly-azureacs

If I understood the tutorial correctly, the same approach should also work for an on-premise environment?

SharePoint App-Only is the older, but still very relevant, model of setting up app-principals. This model works for both SharePoint Online and SharePoint 2013/2016/2019 on-premises and is ideal to prepare your applications for migration from SharePoint on-premises to SharePoint Online.

I could successfully get this whole console application running against our sharepoint online dev-tenant using the following code.

But now when I try to get this running in the SharePoint 2016 environment, it keeps failing.

I did the exact same thing as I did for the SharePoint Online. I created an app (via appnewreg.aspx), granted the same permissions (via appinv.aspx) and exchanged the siteUrl, clientId and clientSecret accordingly.

            string siteUrl = "MySiteUrl";
            string clientId = "ClientId";
            string clientSecret = "ClientSecret";
            using (var clientContext = new AuthenticationManager().GetACSAppOnlyContext(siteUrl, clientId, clientSecret))
            {
                var web = clientContext.Web;
                clientContext.Load(web, w => w.Title);
                clientContext.ExecuteQuery();
                Console.WriteLine(web.Title);
            };

Yet I cant get the console application running.
Receiving the following error:

The remote server returned an error: (400) Bad Request. - {"error":"invalid_request","error_description":"AADSTS90002: Tenant '8a450d28-f099-4c54-bcb9-ddced3a8c499' not found. Check to make sure you have the correct tenant ID and are signing into the correct cloud. Check with your subscription administrator, this may happen if there are no active subscriptions for the tenant.\

So my question is, how can I authenticate within a C# console application with the app-only model? Or is that not possible for SharePoint 2016?

From my understanding, I dont need a provider hosted app for my usecase neither do I need high trust or low trust? Is that correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文