services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = OktaDefaults.ApiAuthenticationScheme;
options.DefaultChallengeScheme = OktaDefaults.ApiAuthenticationScheme;
options.DefaultSignInScheme = OktaDefaults.ApiAuthenticationScheme;
})
.AddOktaWebApi(new OktaWebApiOptions()
{
OktaDomain = _configuration["Okta:OktaDomain"],
});
I have configured my swagger as below :
app.UseSwaggerUI(options =>
{
options.RoutePrefix = "docs";
options.SwaggerEndpoint("/swagger/v1/swagger.json", "Smart Engine API");
options.DefaultModelsExpandDepth(-1);
options.DefaultModelExpandDepth(99);
options.ConfigObject.AdditionalItems.Add("tagsSorter", "alpha");
options.EnableDeepLinking();
options.InjectStylesheet("/docs/overrides.css");
options.OAuthScopeSeparator(",");
options.OAuthUsePkce();
});
options.AddSecurityDefinition("OAuth2", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows
{
Implicit = new OpenApiOAuthFlow
{
AuthorizationUrl = new Uri("https://my.okta.com/oauth2/v1/authorize?nonce=1"),
TokenUrl = new Uri("https://my.okta.com/oauth2/v1/token"),
Scopes = new Dictionary<string, string>
{
{ "openid", "test" },
},
}
},
Description = "Balea Server OpenId Security Scheme"
});
When I click on authorize it is successful, but the generated token has different issuer, and it says " Bearer error=“invalid_token”,error_description=“The signature key was not found” "
The token :
{
"ver": 1,
"jti": "AT.xOnafeU_gKuGyMZD9Ui8WQb0HOBFzdG15tgYaL7sllM",
"iss": "https://my.okta.com",
"aud": "https://my.okta.com",
"sub": "myemaiilAddress",
"iat": 1614972591,
"exp": 1614976233,
"cid": "0oa372abtfziGiBhT5d6",
"uid": "00uaear4itI8ZcELX5d6",
"scp": [
"openid"
]
}
But when I authenticate through Okta login widget I get this token :
{
"ver": 1,
"jti": "AT.ynGuoLqscjtE46cS1EPJqlOBDqMKUaCCA97w6q3TJ6o",
"iss": "https://my.okta.com/oauth2/default",
"aud": "api://default",
"iat": 1614971812,
"exp": 1614975412,
"cid": "0oa372abtfziGiBhT5d6",
"uid": "00uaear4itI8ZcELX5d6",
"scp": [
"profile",
"openid",
"email"
],
"sub": "myemail",
"customerattr": "ttttt",
}
In addition, it is not possible to get custom attributes by using Implicit.