【问题标题】:DocuSign JWT Authentication: Unexpected PEM typeDocuSign JWT 身份验证:意外的 PEM 类型
【发布时间】:2018-12-14 11:03:07
【问题描述】:

由于错误 Unexpected PEM Type,我无法使用 DocuSign 的 OAuth JWT 进行身份验证。我正在使用他们的 Nuget 包 2.2.0。如果我更改为 2.1.10 并稍微调整我的代码,我会收到此错误

Error calling Login: {
    "errorCode": "PARTNER_AUTHENTICATION_FAILED",
    "message": "The specified Integrator Key was not found or is disabled. An Integrator key was not specified."
}

我只有一个沙盒帐户,我已经创建了一个集成密钥。我的重定向 uri 是 https://docusign.com,我创建了一个 RSA 密钥对,我将私钥保存在 PEM 文件中。

我正在按照https://github.com/docusign/docusign-csharp-client/blob/master/README.md 此处的说明进行操作,但OAuth.OAuthToken tokenInfo = apiClient.ConfigureJwtAuthorizationFlowByKey(integratorKey, userId, oauthBasePath, privateKey, expiresInHours); 行引发了异常

我还使用 url https://account-d.docusign.com/oauth/auth?response_type=code&scope=signature%20impersonation&client_id=<integrator-key>&redirect_uri=https://docusign.com 授予对 JWT 的访问权限。

string userId = "e1f43c1a-2546-4317-85a9-cea367f8f92c";
string oauthBasePath = "account-d.docusign.net";
string integratorKey = "<integrator-key>";
string privateKey = @"C:\Users\me\privateKey.pem";
int expiresInHours = 1;
string host = "https://demo.docusign.net/restapi";

【问题讨论】:

    标签: c# oauth jwt docusignapi


    【解决方案1】:

    无论出于何种原因,将userIdoauthBasePathintegratorKeyprivateKeyexpiresInHourshost 都放在一个新类中都有效。

    我还必须传递 PEM 文件的内容而不是文件路径。

     public class FooConfig
    {
        public string Host { get; set; }
    
        public string IntegratorKey { get; set; }
    
        public string UserId { get; set; }
    
        public string OAuthBasePath { get; set; }
    
        public string PrivateKeyFilename { get; set; }
    
        public int ExpiresInHours { get; set; }
    
        public ApiClient ApiClient { get; set; }
    
        public FooConfig()
        {
            this.UserId = "e1f43c1a-2546-4317-85a9-cea367f8f92c";
            this.OAuthBasePath = "account-d.docusign.com";
            this.IntegratorKey = "<integrator-key>";
            this.PrivateKeyFilename = @"C:\Users\me\privateKey.pem";
            this.ExpiresInHours = 1;
            this.Host = "https://demo.docusign.net/restapi";
        }
    }
    
    
    ///////////////////////////////////////////////////////////////////////////////////////
    
    FooConfig testConfig = new FooConfig();
    testConfig.ApiClient = new ApiClient(testConfig.Host);
    
    // If this is the first time logging in - Get Consent from the user - this is a onetime step.
    Uri oauthURI = testConfig.ApiClient.GetAuthorizationUri(testConfig.IntegratorKey, scopes, "https://docusign.com", OAuth.CODE, "testState");
    Process.Start(oauthURI.ToString());
    
    string key = File.ReadAllText(testConfig.PrivateKeyFilename);
    OAuth.OAuthToken tokenInfo = testConfig.ApiClient.ConfigureJwtAuthorizationFlowByKey(testConfig.IntegratorKey, testConfig.UserId, testConfig.OAuthBasePath, key, testConfig.ExpiresInHours);
    

    【讨论】:

    • 请注意,AuthorizationUri 中的 URL 需要与您的集成密钥中的重定向 URL 匹配
    • GetAuthUri +1 - 没有意识到我需要这样的东西,这很有用。我的问题的解决方案是使用 FileReadAllText 而不是 Encoding.Ascii/UTF/etc.GetBytes() 解决的。
    【解决方案2】:

    我遇到了同样的问题,并使用下面的代码解决了它。好像以前的SDK(=2.2.0?),需要文件内容

    testConfig.PrivateKeyFilename = File.ReadAllText("./private.pem");
    
    OAuth.OAuthToken tokenInfo = apiClient.ConfigureJwtAuthorizationFlowByKey
                (testConfig.IntegratorKey, testConfig.UserId, testConfig.OAuthBasePath, testConfig.PrivateKeyFilename, testConfig.ExpiresInHours);
    

    【讨论】:

    • 至少现在在 api 中它的 ConfigureJwtAuthorizationFlow - 采用文件名和 ConfigureJwtAuthorizationFlowByKey 使用密钥数据本身
    • 就像我在回答中提到的,这取决于您使用的 API 版本
    • 其实在2.2.1 DocuSign C# SDK中,该方法被标记为已弃用,建议改用ConfigureJwtAuthorizationFlowByKey方法
    • 是的,升级后,我已经开始使用新的通话了。您通过 byte[] 或 Stream 而不是 string 发送密钥的位置
    【解决方案3】:

    我收到这条消息的最新版本,使用这个方法签名:

    RequestJWTUserToken(_config.ClientId, _config.UserId, $"account-d.docusign.com", _config.Key, 1);
    

    我从网站上复制/粘贴了 .pem 文件的内容。在 Notepad++ 中打开 .pem 并将其编码从 UTF-8 BOM 切换为仅 UTF-8 为我解决了这个错误。

    【讨论】:

      【解决方案4】:

      旧帖子,但也许对某人有帮助:

      我尝试了任何方法都没有成功,然后我发现问题出在“BouncyCastle.Crypto.dll”版本上。 我的项目中似乎有一个旧版本。

      安装最新的(1.9.0)解决了我的问题

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2022-09-26
        • 2018-09-13
        • 1970-01-01
        • 1970-01-01
        • 2020-12-21
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多