Null Reference exception when creating a new OktaClient instance

Hi everyone,

I am using “Okta.Sdk 1.2.1” on a .NET desktop application.
I am simply following these basic steps to authenticate a user:

But i am having a null reference exception when creating a new OktaClient with the following code (I have created the token “Chams” on my API) :

Okta.Sdk.Configuration.OktaClientConfiguration configuration = new Okta.Sdk.Configuration.OktaClientConfiguration
{
OktaDomain = “https://{{dev-702820.okta.com}}”,
Token = “{{Chams}}”
};

var testClient = new OktaClient(configuration);

Here’s the full stack trace of the exception:

at Okta.Sdk.Internal.DefaultProxy…ctor(ProxyConfiguration proxyConfiguration, ILogger logger)
at Okta.Sdk.Internal.DefaultHttpClient.Create(Nullable`1 connectionTimeout, ProxyConfiguration proxyConfiguration, ILogger logger)
at Okta.Sdk.OktaClient…ctor(OktaClientConfiguration apiClientConfiguration, ILogger logger)
at Com.QuodFinancial.FrontEnd.Core.Services.Security.Cryptography.Connection.BeConnectionManager.d__2.MoveNext() in C:\Dev-Projects\Dev_TradingFE\frontend_trunk\Core.Services\Security\Cryptography\Connection\BeConnectionManager.cs:line 118

Maybe the format of my OktaDomain is bad ?

I’ll be grateful for any help or idea :smiley:

how are you getting your token? (also ensure you don’t include the {{}} brackets (i’ve made that mistake before)

Hi @chams,

I agree with @abroadhurst. The brackets are just to indicate placeholders, but you have to remove them when you set your Okta configuration. On the other hand, not sure if Champs if the name you used for your token, but in that case, you have to use the value of the Token and not the name. For example, If your token value were 005vsPQ6kA76hbUvcwTF4cHwkj28zSo9M7ZZozKyyz your OktaClient configuration should look like this:

Okta.Sdk.Configuration.OktaClientConfiguration
{
OktaDomain = “https://dev-702820.okta.com”,
Token = “005vsPQ6kA76hbUvcwTF4cHwkj28zSo9M7ZZozKyyz”
};

I hope this helps!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.