Rui Barbosa
Rui Barbosa

Reputation: 47

Using Azure Active Directory to access other services

I have azure active directory authentication in my Web API and I want to connect to other services as Dynamics NAV and Sharepoint using azure ad credentials.

The code to access Sharepoint is the following:

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

And the code to access the Dynamics NAV is the following:

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

The problem is that I have to enter manually user credentials to access the Sharepoint and NAV services. Is there any way to do this dynamically? Using entered azure ad credentials.

Upvotes: 2

Views: 356

Answers (1)

Fei Xue
Fei Xue

Reputation: 14649

AFAIK, the Dynamics NAV supports OAuth authentication with Azure Active Directory. In this scenario, you can use the on-behalf-of flow which requires users enter the username/password to get the access token to access the web API. Then the web API can exchange the access token for Dynamics NAV and call the Dynamics NAV. Here is a figure to demonstrate this scenario(refer here): enter image description here

And for the SharePoint, you can use Microsoft Graph. More detail about oauth for the Dynamics NAV and Microsoft Graph, you can refer the link below:

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

Get access tokens to call Microsoft Graph

And for the code sample for the on-behalf-of flow, you can refer the code sample below:

active-directory-dotnet-webapi-onbehalfof

Upvotes: 2

Related Questions