Sam*_*til 5 dotnet-httpclient azure-active-directory asp.net-core refresh-token microsoft-graph-api
按照此过程操作: https://learn.microsoft.com/en-us/graph/auth-v2-user
我正在尝试从此 Microsoft 端点获取刷新令牌: https://login.microsoftonline.com/ {tenantId}/oauth2/v2.0/authorize
使用nuget (asp.net core 2.2) 库中System.Net.Http.HttpClient类的 PostAsync 方法,我能够收到以下错误的响应:“AADSTS90102:'redirect_uri'值必须是有效的绝对 Uri。 ” :

我尝试在 Azure 门户中设置一些重定向 url,包括:
https://automation.legroupeti.com/Configurations/GetRefreshToken/
https://automation.legroupeti.com/Configurations/GetRefreshToken
https://automation.legroupeti.com/
https://automation.legroupeti.com
post 请求如下(使用nuget (asp.net core 2.2) 中System.Net.Http.HttpClient类的 PostAsync 方法):

以下是在 Azure 门户中注册的应用程序配置的重定向 URL:

我期望来自端点的有效响应。如何配置redirect_uri才有效?
编辑1
我修复了redirect_uri参数。
我收到此错误,对我来说问题是我正在redirect_uri对端点的发布请求中的值进行编码/oauth2/v2.0/token。redirect_uri请注意此请求中未编码的方式。
POST /{Tenant ID}/oauth2/v2.0/token HTTP/1.1
Host: login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
Cookie: {cookie}
Content-Length: 941
client_id={Application (client) ID}
&scope=https://graph.microsoft.com/mail.read
&redirect_uri=http://localhost/myapp/
&grant_type=authorization_code
&client_secret={secret}
&code={code}
Run Code Online (Sandbox Code Playgroud)
我使用微软提供的Postman示例来查找根本原因。
您似乎混合了授权和令牌端点。
如果您希望用户进行身份验证,则必须将用户重定向到该 URL,而不是向其发送 POST 请求。当用户返回您的应用后,您需要将授权码兑换为令牌。文档:https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-web-app-call-api-overview
如果您想要仅用于您的应用程序而不需要用户身份验证的令牌,则需要调用令牌端点。文档:https ://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-daemon-overview
| 归档时间: |
|
| 查看次数: |
28195 次 |
| 最近记录: |