[英]Managing access from a Console App to a Web API on Azure
I have an Angular application deployed on Azure secured with Azure Active Directory. 我有一个用Azure Active Directory保护的Azure上部署的Angular应用程序。 To achieve that, I have followed this guide : https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-devquickstarts-angular .
为此,我遵循了本指南: https : //docs.microsoft.com/zh-cn/azure/active-directory/develop/active-directory-devquickstarts-angular 。
So, in order to query the website's Web API, the user needs to be authenticated on Azure Active Directory. 因此,为了查询网站的Web API,需要在Azure Active Directory上对用户进行身份验证。 So far, everything works great.
到目前为止,一切正常。
Now, we have a internal service, not deployed on Azure, that needs to query a method of that Web API, which is already secured as previously mentioned. 现在,我们有一个内部服务(未部署在Azure上),需要查询该Web API的方法,该方法已如前所述被保护。
Is there a way, without using the Api Management service, to give access to the internal service in order to call the secured Web API without having the need to use a AAD username / password? 有没有一种方法,无需使用Api管理服务,就可以访问内部服务,从而无需使用AAD用户名/密码即可调用受保护的Web API?
I tried using ADAL librairy, but all the example that I have seen prompt an AAD username password login. 我尝试使用ADAL librairy,但是我看到的所有示例都提示输入AAD用户名密码。
To call the web API which protected by Azure AD without interaction to provide username and password, we can use the Client Credentials flow( refer this document ). 要调用不受Azure AD保护的Web API,而无需交互以提供用户名和密码,我们可以使用客户端凭据流(请参阅本文档 )。
And there is the code to use the azure-activedirectory-library-for-dotnet for your reference: 并且有使用azure-activedirectory-library-for-dotnet的代码供您参考:
string authority = "https://login.microsoftonline.com/{tenantId}";
string clientId = "";
string secret = "";
string resource = "";
var credential = new ClientCredential(clientId, secret);
AuthenticationContext authContext = new AuthenticationContext(authority);
var token = authContext.AcquireTokenAsync(resource, credential).Result.AccessToken;
Console.WriteLine(token);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.