使用Azure Active Directory访问其他服务

时间:2017-07-17 13:47:15

标签: azure authentication sharepoint authorization azure-active-directory

我的Web API中有azure Active Directory身份验证,我想使用azure广告凭据连接到Dynamics NAV和Sharepoint等其他服务。

访问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服务。有没有办法动态地这样做?使用输入的azure广告凭证。

1 个答案:

答案 0 :(得分:2)

AFAIK,Dynamics NAV支持使用Azure Active Directory进行OAuth身份验证。在这种情况下,您可以使用代表流,这需要用户输入用户名/密码以获取访问令牌以访问Web API。然后,Web API可以交换Dynamics NAV的访问令牌并调用Dynamics NAV。这是一个演示这种情况的图(参考here): enter image description here

对于SharePoint,您可以使用Microsoft Graph。有关Dynamics NAV和Microsoft Graph的oauth的更多详细信息,请参阅以下链接:

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

Get access tokens to call Microsoft Graph

对于代表流的代码示例,您可以参考下面的代码示例:

active-directory-dotnet-webapi-onbehalfof