Create a jwt token in C# with public private key of Okta

309 Views Asked by At

I've successfully set up an application on the Okta portal, configured it to use the "Client Credentials" OAuth 2.0 grant type, and obtained a public-private key pair. I'm currently trying to generate and validate a token in C# using the private key from Okta.

Here's what I've tried so far in C# to validate the token:

services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
    .AddJwtBearer(options =>
    {
        options.TokenValidationParameters = new TokenValidationParameters
        {
            ValidateIssuer = true,
            ValidIssuer = "myIssuer",
            ValidateAudience = true,
            ValidAudience = "myAudience",
            ValidateLifetime = true
        };
    });

When I run this code, I get a 'token invalid' message without any additional details. Could someone guide me through the process of generating and validating a token with Okta or point me to resources that could help me solve this issue? I need to use Client credentials because I don't have users in Okta, I need this token when calling an API just to secure my api. Thank you!

0

There are 0 best solutions below