【发布时间】:2021-02-12 10:52:52
【问题描述】:
我已在我的测试项目中将 DocuSign eSign NuGet 包从 4.1.1 升级到最新版本 5.1.0。
测试代码:
var auth = DocuSign.eSignature.JWTAuth.AuthenticateWithJWT();
string accessToken = auth.accessToken;
string accountId = auth.accountId;
string basePath = auth.baseUri;
var config = new Configuration(basePath);
config.AddDefaultHeader("Authorization", "Bearer " + accessToken);
EnvelopeDefinition envelope = MakeEnvelope("user@somecompany.com", "User Name", "",
"", "15ffda8-5953-4e5f-b9d6-112133adf0e7");
var envelopesApi = new EnvelopesApi(new ApiClient(config));
EnvelopeSummary result = envelopesApi.CreateEnvelope(accountId, envelope);
但是,从那时起,我在运行代码时收到以下错误:
DocuSign.eSign.Client.ApiException: '调用 CreateEnvelope 时出错:{"errorCode":"USER_AUTHENTICATION_FAILED","message":"用户名和密码中的一个或两个无效。访问令牌无效"}'
我从 DocuSign 获得了 AuthenticateWithJWT() 方法:
public static (string accessToken, string accountId, string baseUri) AuthenticateWithJWT()
{
var apiClient = new ApiClient();
string ik = ConfigurationManager.AppSettings["IntegrationKey"];
string userId = ConfigurationManager.AppSettings["userId"];
string authServer = ConfigurationManager.AppSettings["AuthServer"];
string rsaKey = ConfigurationManager.AppSettings["RSAKey"];
OAuth.OAuthToken authToken = apiClient.RequestJWTUserToken(ik,
userId,
authServer,
Encoding.UTF8.GetBytes(rsaKey),
1);
string accessToken = authToken.access_token;
apiClient.SetOAuthBasePath(authServer);
OAuth.UserInfo userInfo = apiClient.GetUserInfo(authToken.access_token);
Account acct = null;
var accounts = userInfo.Accounts;
{
acct = accounts.FirstOrDefault(a => a.IsDefault == "true");
}
string accountId = acct.AccountId;
string baseUri = acct.BaseUri + "/restapi";
return (accessToken, accountId, baseUri);
}
它像以前一样正确返回了我的 accountId、访问令牌和基本路径。
关于可能导致此错误的原因或我可能会采取哪些步骤来进一步解决此问题的任何想法?
【问题讨论】:
标签: c# .net oauth jwt docusignapi