我正在尝试从 Microsoft 帐户使用 SSO,这在请求授权中进行了解释。
我已经完成注册应用程序并请求授权,因此我从 Microsoft 进行编码,但我无法获取请求访问令牌,Microsoft 给出的示例如下:
// Line breaks for legibility only
POST /{tenant}/oauth2/v2.0/token HTTP/1.1
Host: https://login.microsoftonline.com
Content-Type: application/x-www-form-urlencoded
client_id=11111111-1111-1111-1111-111111111111
&scope=user.read%20mail.read
&code=OAAABAAAAiL9Kn2Z27UubvWFPbm0gLWQJVzCTE9UkP3pSx1aXxUjq3n8b2JRLk4OxVXr...
&redirect_uri=http%3A%2F%2Flocalhost%2Fmyapp%2F
&grant_type=authorization_code
&client_secret=HF8Q~Krjqh4r... // NOTE: Only required for web apps
我使用 RestSharp 编写了这段代码:
string URI = "https://login.microsoftonline.com/organizations/oauth2/v2.0/token";
string myParameters = "client_id="+clientID+"&scope=User.Read%20Mail.Read&code=" + code + "&redirect_uri=http%3A%2F%2Flocalhost:8756%2FStep1Resp.aspx&grant_type=authorization_code&client_secret="+clientSec;
var client = new RestClient(URI);
var request = new RestRequest(Method.POST);
request.AddHeader("cache-control", "no-cache");
request.AddHeader("content-type", "application/x-www-form-urlencoded");
request.AddParameter("application/x-www-form-urlencoded", myParameters, ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
string resp=response.Content;
我收到错误
底层连接已关闭:发送时发生意外错误。
我的错误在哪里?