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