我尝试了不同的方式来传递header
和content
,但是每次从bad request
获取docusign
来获取访问令牌。
下面是回调Web API方法,该方法在请求authorization code
之后被调用:
[HttpGet]
[AllowAnonymous]
[Route("CallBack")]
public string Callback()
{
string accessToken = "";
try
{
var response = Request.Query;
if (Request.Query != null && Request.Query.Keys != null && Request.Query.Keys.Count > 0)
{
var authorizationCode = Request.Query["code"];
/*
Request => POST https://account-d.docusign.com/oauth/token
Content-Type: application/x-www-form-urlencoded
Header => Authorization: Basic BASE64_COMBINATION_OF_INTEGRATOR_AND_SECRET_KEYS
Data => grant_type=authorization_code&authorization_code=YOUR_AUTHORIZATION_CODE
*/
//Body
var keyValues = new Dictionary<string, string>();
keyValues.Add("grant_type", "authorization_code");
keyValues.Add("authorization_code", authorizationCode);
var bodyContent = new FormUrlEncodedContent(keyValues);
//Header
//Content-Type: application/x-www-form-urlencoded
//Authorization: Basic BASE64_COMBINATION_OF_INTEGRATOR_AND_SECRET_KEYS
string base64Decoded = configuration.IntegrationKey + ":" + configuration.SecretKey;
string base64Encoded;
byte[] data = System.Text.ASCIIEncoding.ASCII.GetBytes(base64Decoded);
base64Encoded = System.Convert.ToBase64String(data);
var client = new System.Net.Http.HttpClient();
client.BaseAddress = new Uri("https://account-d.docusign.com");
var request = new System.Net.Http.HttpRequestMessage(HttpMethod.Post, "https://account-d.docusign.com/oauth/token");
request.Content = bodyContent;
request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/x-www-form-urlencoded");
request.Headers.Authorization = new AuthenticationHeaderValue("Basic", base64Encoded);
var accessTokenresponse = client.SendAsync(request).Result;
//Set access token
//accessToken
}
}
catch (Exception ex)
{
}
return accessToken;
}
答案 0 :(得分:1)
一些适合您的想法:
state
参数中发送一个现时值,然后在从DocuSign收到第一个响应时检查它是否相同。