“错误代码”:“ PARTNER_AUTHENTICATION_FAILED”

时间:2018-08-06 15:15:24

标签: c# docusignapi

运行DocuSign的演示代码时出现以下错误 DocuSign.eSign.Client.ApiException:'调用登录时出错:{   “ errorCode”:“ PARTNER_AUTHENTICATION_FAILED”,   “ message”:“找不到或禁用了指定的集成商密钥。未指定集成商密钥。” }'

我正在运行的以下代码直接来自演示应用程序,用于使用API​​

这是我正在运行的代码的片段

static string CreateDocuSignEnvelope()
{
    string userId = ConfigurationManager.AppSettings["UserId"];
    string oauthBasePath = ConfigurationManager.AppSettings["OAuthBasePath"];
    string integratorKey = ConfigurationManager.AppSettings["IntegratorKey"];
    string privateKeyFilename = AppContext.BaseDirectory + "PrivateKey.pem";
    string host = ConfigurationManager.AppSettings["Host"];
    string templateId = ConfigurationManager.AppSettings["TemplateID"];
    int expiresInHours = 1;

    //string accountId = string.Empty;
    string pfName = System.IO.File.ReadAllText(privateKeyFilename);

    ApiClient apiClient = new ApiClient(host);
    //apiClient.ConfigureJwtAuthorizationFlowByKey(integratorKey, userId, oauthBasePath, privateKeyFilename, expiresInHours);
    apiClient.ConfigureJwtAuthorizationFlowByKey(integratorKey, userId, oauthBasePath, pfName, expiresInHours);
    /////////////////////////////////////////////////////////////////
    // STEP 1: LOGIN API        
    /////////////////////////////////////////////////////////////////
    AuthenticationApi authApi = new AuthenticationApi(apiClient.Configuration);
    LoginInformation loginInfo = authApi.Login();

    // find the default account for this user
    foreach (LoginAccount loginAcct in loginInfo.LoginAccounts)
    {
        if (loginAcct.IsDefault == "true")
        {
            accountID = loginAcct.AccountId;

            string[] separatingStrings = { "/v2" };

            // Update ApiClient with the new base url from login call
            apiClient = new ApiClient(loginAcct.BaseUrl.Split(separatingStrings, StringSplitOptions.RemoveEmptyEntries)[0]);
            break;
        }
    }
}

LoginInformationLoginInfo = authApi.Login();失败,我们将不胜感激。

1 个答案:

答案 0 :(得分:1)

由于您使用的是OAuth身份验证,因此authApi.Login()方法无法正常工作。仅用于传统身份验证。

您将要使用GetUserInfo()方法来获取所需的帐户信息。这是C# Client Github

的更新示例
        ApiClient apiClient = new ApiClient(host);
        OAuth.OAuthToken tokenInfo = apiClient.ConfigureJwtAuthorizationFlowByKey(integratorKey, userId, oauthBasePath, privateKey, expiresInHours);

        OAuth.UserInfo userInfo = apiClient.GetUserInfo(tokenInfo.access_token);

        foreach (var item in userInfo.GetAccounts())
        {
            if (item.GetIsDefault() == "true")
            {
                accountId = item.AccountId();
                apiClient = new ApiClient(item.GetBaseUri() + "/restapi");
                break;
            }
        }

        EnvelopesApi envelopesApi = new EnvelopesApi(apiClient.Configuration);