简体   繁体   English

https://management.azure.com/tenants api using asp.net core and c# code return The remote server returned an error: (401) Unauthorized

[英]https://management.azure.com/tenants api using asp.net core and c# code return The remote server returned an error: (401) Unauthorized

I want to call https://management.azure.com/tenants?api-version=2020-01-01 api to call to get tenant list in my project, using asp.net and c#, but not able to get valid link. I want to call https://management.azure.com/tenants?api-version=2020-01-01 api to call to get tenant list in my project, using asp.net and c#, but not able to get valid link. if possible share sample of this.如果可能的话,分享这个样本。

I know how to call api, the problem is I dont get proper response, I have refer below link to call api, but after calling organization api get exception 'The remote server returned an error: (401) Unauthorized.'我知道如何调用 api,问题是我没有得到正确的响应,我参考下面的链接来调用 api,但是在调用组织 api 后得到异常'远程服务器返回'未授权'错误:

I have taken Token using GetAccessToken() method我已经使用 GetAccessToken() 方法获取了 Token

https://msftstack.wordpress.com/2016/01/03/how-to-call-the-azure-resource-manager-rest-api-from-c/ https://msftstack.wordpress.com/2016/01/03/how-to-call-the-azure-resource-manager-rest-api-from-c/

I got below information from Token我从 Token 得到以下信息

在此处输入图像描述

To call this api, you need to genenate an access token for this api.要调用此 api,您需要为此 api 生成访问令牌。 To generate this token, you need an azure ad app with the specific api permission.要生成此令牌,您需要具有特定 api 权限的 azure 广告应用程序。 For your 401 error, it's likely has wrong permission or does't contain the scope.对于您的 401 错误,可能是权限错误或不包含 scope。 You can debug your code and copy the access token and go to https://jwt.io/ to generate it.您可以调试代码并将访问令牌和 go 复制到https://jwt.io/以生成它。

Check if your token has the correct aud https://management.azure.com and scope user_impersonation :检查您的令牌是否具有正确的 aud https://management.azure.com和 Z31A1FD140BE4BEF2D58A user1E

Here's the detail on this api and I'll show you my detail on it.这是api 的详细信息,我将向您展示我的详细信息。

在此处输入图像描述 在此处输入图像描述

Because of the delegated permission, you need to generate token via a user with ropc flow or auth code flow(this means not only the azure ad app, but you also need to use user name and password in the process of generating access token).由于委托权限,需要通过ropc流或auth码流的用户生成token(这不仅指azure广告app,在生成access token的过程中还需要使用用户名和密码)。

I think you can find a sample in this official document .我想你可以在这个官方文档中找到一个示例。

If you'd like you generate token and call api in your angular app, you can refer to this sample , pls note the sample calls graph api如果您想生成令牌并在 angular 应用程序中调用 api,您可以参考此示例,请注意示例调用图 api

在此处输入图像描述

If you prefer to call api in the backend app, you can send the token to the backend program because daemon applications only supports client credential flow.如果您更喜欢在后端应用程序中调用 api,您可以将令牌发送到后端程序,因为守护程序应用程序仅支持客户端凭据流。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 远程服务器返回错误:(401)在context.ExecuteQuery()中未经授权:ASP.Net - The remote server returned an error: (401) Unauthorized in context.ExecuteQuery() : ASP.Net C# 远程服务器返回错误:(401) Unauthorized - C# The remote server returned an error: (401) Unauthorized ASP.NET Core 3.1 如何使用 Azure AD B2C 返回 401 Unauthorized 而不是 Challenge - ASP.NET Core 3.1 how to return 401 Unauthorized instead of Challenge with Azure AD B2C asp.net c#Google api文档-401未经授权 - asp.net c# google api Documents - 401 Unauthorized Box API返回错误::远程服务器返回错误:(401)未经授权 - Box API returned Error : : The remote server returned an error: (401) Unauthorized Twitter API集成-远程服务器返回错误:(401)未经授权 - Twitter API Integration - The remote server returned an error: (401) Unauthorized Twitter搜索API远程服务器返回错误:(401)未经授权 - Twitter Search API The remote server returned an error: (401) Unauthorized REST Search API远程服务器返回错误:(401)未经授权 - REST Search API The remote server returned an error: (401) Unauthorized 出现错误:远程服务器返回错误:(401)未经授权。 ,同时将我的网站评论发布到Twitter。 使用C# - Getting error : The remote server returned an error: (401) Unauthorized. , while posting my website comments to twitter. Using C# 简单的API调用management.azure.com - Simple API call to management.azure.com
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM