PKISharp / ACMESharpCore

An ACME v2 client library for .NET Standard (Let's Encrypt)
MIT License
325 stars 72 forks source link

System.Private.Uri: Value cannot be null when creating a new account #37

Closed crhistianramirez closed 4 years ago

crhistianramirez commented 4 years ago

When I execute this code I get the following errors on await _client.GetNonceAsync(). Am I missing something?

Error:

System.Private.CoreLib: Exception while executing function: RenewCertificates. System.Private.Uri: Value cannot be null. Parameter name: uriString.

// initialize client
var acmeApiUrl = new Uri("https://acme-staging-v02.api.letsencrypt.org/");
var acme = new AcmeProtocolClient(acmeApiUrl );

// verify directory.NewNonce exists
var directory = await _client.GetDirectoryAsync();
Console.WriteLine(directory.NewNonce); // https://acme-staging-v02.api.letsencrypt.org/acme/new-nonce

// get nonce, used to communicate w/ server
await _client.GetNonceAsync();

// make request to create account
var contactEmails = new string[] { "mailto:test@test.com" };
var account = await _client.CreateAccountAsync(contactEmails, termsOfServiceAgreed: true);
var accountKey = new WinmarkAccountKey {
    KeyType = _client.Signer.JwsAlg,
    KeyExport = _client.Signer.Export()
};

// store account details
Console.WriteLine(account);
Console.WriteLine(accountKey);
_client.Account = account;
ebekker commented 4 years ago

After you get the directory, you need to assign it to the client, in your case:

_client.Directory = directory;