Azure开发者如何解决CURL请求Oauth2 Token时返回404 Not Found的问题?
- 内容介绍
- 文章标签
- 相关推荐
本文共计354个文字,预计阅读时间需要2分钟。
问题描述:在使用Postman向AAD发送请求时,请求得到404 Not Found错误。
使用方法:
1.打开Postman。
2.创建一个新的请求。
3.设置请求类型为POST。
4.输入以下URL:https://login.chinacloudapi.cn/oauth2/token
5.在请求头中添加以下内容:
- Content-Type: application/x-www-form-urlencoded6.在请求体中添加以下内容:
- grant_type=client_credentials - client_id=你的客户端ID - client_secret=你的客户端密钥7.发送请求。
错误提示:404 Not Found
问题描述
当使用 Postman 向AAD 发送如下请求时候,得到了404 Not Found的错误。
"curl --location --request POST 'login.chinacloudapi.cn//oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=' \
--data-urlencode 'client_secret=' \
--data-urlencode 'resource=management.chinacloudapi.cn'"
问题分析
404 表示所请求的URL有错误, 查看以上命令使用的为'login.chinacloudapi.cn//oauth2/token' ,发现在Oauth2之前,缺少了AAD的Tenant ID信息。所以,完整的Token URL应是:
login.chinacloudapi.cn/{Tenant ID}/oauth2/token
在AAD门户中Tenant ID 及正确的Token URL为:
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!
本文共计354个文字,预计阅读时间需要2分钟。
问题描述:在使用Postman向AAD发送请求时,请求得到404 Not Found错误。
使用方法:
1.打开Postman。
2.创建一个新的请求。
3.设置请求类型为POST。
4.输入以下URL:https://login.chinacloudapi.cn/oauth2/token
5.在请求头中添加以下内容:
- Content-Type: application/x-www-form-urlencoded6.在请求体中添加以下内容:
- grant_type=client_credentials - client_id=你的客户端ID - client_secret=你的客户端密钥7.发送请求。
错误提示:404 Not Found
问题描述
当使用 Postman 向AAD 发送如下请求时候,得到了404 Not Found的错误。
"curl --location --request POST 'login.chinacloudapi.cn//oauth2/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'client_id=' \
--data-urlencode 'client_secret=' \
--data-urlencode 'resource=management.chinacloudapi.cn'"
问题分析
404 表示所请求的URL有错误, 查看以上命令使用的为'login.chinacloudapi.cn//oauth2/token' ,发现在Oauth2之前,缺少了AAD的Tenant ID信息。所以,完整的Token URL应是:
login.chinacloudapi.cn/{Tenant ID}/oauth2/token
在AAD门户中Tenant ID 及正确的Token URL为:
当在复杂的环境中面临问题,格物之道需:浊而静之徐清,安以动之徐生。 云中,恰是如此!

