docusignapi - 尝试使用docusign API获取authToken时出现错误请求
问题描述
我是 docuSign API 的新手,我按照 DocuSign 指南站点中的 C# 代码示例进行操作。我在尝试获取 AuthToken 时在这一步失败了。我的部分代码如下,与DocuSign示例基本相同,
public void OAuthAuthorizationCodeFlowTest()
{
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
// Make an API call with the token
ApiClient apiClient = new ApiClient(RestApiUrl);
DocuSign.eSign.Client.Configuration.Default.ApiClient = apiClient;
// Initiate the browser session to the Authentication server
// so the user can login.
string accountServerAuthUrl =
apiClient.GetAuthorizationUri(client_id, redirect_uri, true,
stateOptional);
System.Diagnostics.Process.Start(accountServerAuthUrl);
string accessToken = apiClient.GetOAuthToken(client_id,
client_secret, true, AccessCode);
// login call is available in the authentication api
AuthenticationApi authApi = new AuthenticationApi();
LoginInformation loginInfo = authApi.Login();
// parse the first account ID that is returned (user might belong to
multiple accounts)
AccountId = loginInfo.LoginAccounts[0].AccountId;
BaseUri = loginInfo.LoginAccounts[0].BaseUrl;
Console.WriteLine("accountId: " + AccountId);
Console.WriteLine("base_uri: " + BaseUri);
client_id 是我的集成密钥,client_secret 是与该集成密钥相关的密钥,对吧?我检查了很多次,没有问题。我现在很困惑,为什么我仍然收到 400 错误。请在这里给我一些启发,谢谢!!!
解决方案
System.Diagnostics.Process.Start(accountServerAuthUrl);
将在浏览器上打开它,一旦您成功完成身份验证,浏览器将使用code=....
回调 url ( redirect_uri
)中的查询参数重定向
浏览器中的代码需要被你的WEBApp读取,然后你需要调用下面的代码来生成AccessToken:
string accessToken = apiClient.GetOAuthToken(client_id,
client_secret, true, AccessCode);
下面的代码是打开浏览器的一部分,理想情况下它是为了在独立系统上进行测试,在 WEBApp 上,您将浏览器重定向到accountServerAuthUrl
public void OAuthAuthorizationCodeFlowTest()
{
// Make an API call with the token
ApiClient apiClient = new ApiClient(RestApiUrl);
DocuSign.eSign.Client.Configuration.Default.ApiClient = apiClient;
// Initiate the browser session to the Authentication server
// so the user can login.
string accountServerAuthUrl = apiClient.GetAuthorizationUri(client_id, redirect_uri, true, stateOptional);
System.Diagnostics.Process.Start(accountServerAuthUrl);
}
下面的代码在用户通过浏览器上的 DocuSign 身份验证并且浏览器被重定向到redirect_uri
with 时运行code=...
,您的 Webapp 将读取此代码并将其发送AccessCode
并从您的控制器调用下面的代码,
string accessToken = apiClient.GetOAuthToken(client_id, client_secret, true, AccessCode);
推荐阅读
- list - SharePoint Online 列表视图
- docker - 重新创建时 Docker 服务无法相互解析
- google-cloud-storage - BigQuery Transfer Service 界面 - run_date 参数
- microsoft-cognitive - 必应新闻搜索 API 语言翻译结果?
- networkx - 如何从networkx的Louvain社区检测算法中得到一个真实的树状图?
- reactjs - reactjs-如何从父组件获取axios响应数据到子组件
- node.js - 如何在 aws S3 中获取 ObjectURL 作为响应
- tensorflow - 损失函数将 y_pred 转换为张量,这意味着模型的输出不能是 RaggedTensor 类型
- centos - cpack 限制操作系统版本包可以安装在
- html - 如果在 HTML 中选中复选框,我如何附加一个值?