简体   繁体   English

管理从控制台应用程序到Azure上的Web API的访问

[英]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.

相关问题 授权angular.js应用程序访问由Azure Active Directory身份验证保护的Web API 2项目 - Authorize an angular.js app to access a Web API 2 project secured by Azure Active Directory auth 验证站点/应用程序以访问Web API服务 - Authenticate a site/app to access a Web API Service 在AAD安全Azure Web App中检索访问令牌 - Retrieve Access Token within a AAD secured Azure Web App Javascript:如何通过网络应用程序使用Google API访问“特定用户”数据? - Javascript: how to access *specific user* data with Google API from web app? 从Web API将数据获取到Angular应用中 - Getting data into Angular app from Web API 从AngualrJS应用隐藏API访问凭据 - Hiding API access credentials from an AngualrJS app 如何知道 web 应用程序可在浏览器或团队自定义应用程序上访问 - How to know that web app is access on browser or from teams custom app 在ASP.NET中管理AngularJS Web应用程序(RequireJS的替代方案) - Managing an AngularJS web app within ASP.NET (alternative to RequireJS) 从 web api 获取 http 错误 500 访问被拒绝 - Getting http error 500 access denied from web api 使用$ resource从AngularJs中的Web API访问HttpResponseMessage - Access HttpResponseMessage from Web API in AngularJs using $resource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM