Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DocuSign JWT Authentication: Unexpected PEM type

I can't authenticate with DocuSign's OAuth JWT because of the error Unexpected PEM Type. I'm using their Nuget package 2.2.0. If I change to 2.1.10 and tweak my code slightly I get this error

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

I only have a Sandbox account, which I have created an Integrator Key. My redirect uri is https://docusign.com and I created an RSA Keypair which I saved the private key in a PEM file.

I'm following the instructions here https://github.com/docusign/docusign-csharp-client/blob/master/README.md but an exception is raised on the line OAuth.OAuthToken tokenInfo = apiClient.ConfigureJwtAuthorizationFlowByKey(integratorKey, userId, oauthBasePath, privateKey, expiresInHours);

I have also granted access to JWT using the url https://account-d.docusign.com/oauth/auth?response_type=code&scope=signature%20impersonation&client_id=<integrator-key>&redirect_uri=https://docusign.com.

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";
like image 290
zach attack Avatar asked Oct 16 '22 16:10

zach attack


1 Answers

For whatever reason sticking the userId, oauthBasePath, integratorKey, privateKey, expiresInHours and host all in a new class worked.

I also had to pass the contents of the PEM file instead of the file path.

 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);
like image 81
zach attack Avatar answered Oct 21 '22 00:10

zach attack