2

我在Web API中使用Azure Active Directory身份驗證,並且想使用Azure廣告憑據連接到其他服務,例如Dynamics NAV和Sharepoint。使用Azure Active Directory訪問其他服務

訪問SharePoint中的代碼如下:

ClientContext clientContext = new ClientContext(siteUrl); 
clientContext.Credentials = new SharePointOnlineCredentials(Email, Password); 

並訪問Dynamics NAV的代碼如下:

NAV.NAV nav = new NAV.NAV(URL); 
nav.Credentials = new NetworkCredential(Email, Password, Domain); 

的問題是,我必須手動輸入用戶憑據訪問Sharepoint和NAV服務。有沒有辦法動態地做到這一點?使用輸入的天藍色廣告憑據。

回答

2

AFAIK,Dynamics NAV支持使用Azure Active Directory進行OAuth身份驗證。在這種情況下,您可以使用代表流程,該流程要求用戶輸入用戶名/密碼以獲取訪問令牌以訪問Web API。然後,Web API可以交換Dynamics NAV的訪問令牌並調用Dynamics NAV。下面是演示此場景的圖(參考here): enter image description here

而對於SharePoint,您可以使用Microsoft Graph。瞭解OAuth的動態NAV和Microsoft Graph的更多細節,你可以參考以下鏈接:

Using OAuth to Authenticate Microsoft Dynamics NAV Web Services (OData and SOAP)

Get access tokens to call Microsoft Graph

和爲上代表-的流量,你可以參考的代碼示例代碼示例如下:

active-directory-dotnet-webapi-onbehalfof