[英]How to authenticate correctly in SharePoint Online from Azure Function with API Graph?
再見,
我正在處理 Azure Function 需要使用 API Graph 讀取/寫入 SharePoint 在線列表。 我在身份驗證方面遇到了一些問題。
我已按照以下步驟操作:
下面的應用程序的授權:
在我的代碼下面:
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "my-tenant-id";
var clientId = "my-client-id";
var clientSecret = "my-secret";
var clientSecretCredential = new ClientSecretCredential(tenantId, clientId, clientSecret);
var graphServiceClient = new GraphServiceClient(clientSecretCredential, scopes);
var test = await graphServiceClient
.Sites["my-site-id"]
.Lists["my-list-id"]
.Items.Request().GetAsync();
當我執行此代碼時,出現此錯誤:消息:令牌中需要存在 scp 或角色聲明。
我該如何解決這個錯誤?
萬分感謝
我試圖在我的環境中重現相同的內容並得到如下相同的錯誤:
為了解決這個錯誤,我創建了一個Azure AD 應用程序並授予 API 權限,如下所示:
請注意,您只能根據需要添加Sites.Selected
API 權限。
我使用以下參數生成了 scope 作為https://graph.microsoft.com/.default
的令牌:
https://login.microsoftonline.com/TenantID/oauth2/v2.0/token
client_id:ClientID
client_secret:ClientSecret
scope:https://graph.microsoft.com/.default
grant_type:client_credentials
使用上面生成的訪問令牌,我可以像下面這樣成功地對 SharePoint 進行身份驗證:
https://graph.microsoft.com/v1.0/sites/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.