I am using OpenIddict in .Net Core 6.0 for token-based authentication and authorization for my REST/Web API It works within Visual Studio IIS Express but not on my Local IIS server.
When I call the Token API using Visual Studio's IIS Express, I get the correct token in the response
Request: POST - http://localhost:5023/token
BODY - x-www-form-urlencoded client_id:xxxxx client_secret:xxxxxx grant_type:client_credentials
Response:
{
"access_token": "eyJhbGciOiJSUzI1NiIsImtpZCI6IkYzNTYzRTU0OTkwNEZFOENFRjg2NkI1RjRCNjc1MDU0NzFGQjcwQjciLCJ4NXQiOiI4MVktVkprRV9venZobXRmUzJkUVZISDdjTGMiLCJ0eXAiOiJhdCtqd3QifQ.eyJzdWIiOiJrYW1hbCIsIm5hbWUiOiJrYW1hbCIsIm9pX3Byc3QiOiJrYW1hbCIsImNsaWVudF9pZCI6ImthbWFsIiwib2lfdGtuX2lkIjoiNThiYWJkODctNmFjZC00MTc2LWIxNTctMGE2YWNlMGRkMjY3IiwianRpIjoiOTBlOWNmOWItNjNjMi00MDVhLTk3ZjQtM2Q4YjQyYTEwMjI3IiwiZXhwIjoxNjc4NzkyNDY1LCJpc3MiOiJodHRwOi8vbG9jYWxob3N0OjUwMjMvIiwiaWF0IjoxNjc4Nzg4ODY1fQ.fj7iNpDrESf6duOIaPKEiL1wmSsMaHUVJpkEsY0LlE-4KVfplnkEtfVOXpF3B-NyEtbwEZnGKadtXMEBAs2168p8egkDe-X2Kkc1jJPv0joO_iJlcBXdT4e0kLQr-L8j3b0Cro1hw7K1FQimgwR04PIPqVOj4m4Q0xzge7-Ism5-i-JYtuIdGQNt2gfd-z_DTjIuV3zHXLv0qVGu6uv5b0aCM0EZFuzXOg_4WurqwM68I4lhHycS5KI2NiqRJnubA6de_uwjsVwzKvNOA_q5MG6XXh3xy8v_NwL4qrDPZj3mO9VXc2RZDYt4IIeASNTlpJ9e92Q89odF3ZTYrnh_yA",
"token_type": "Bearer",
"expires_in": 3599
}
However, when I call the Token API using Local IIS Server, I get the the 500 Internal Server error. On debugging I found that in the method public async Task Exchange(), request object is set as null in the following line:
var request = HttpContext.GetOpenIddictServerRequest();
This is how I setup OpenIddict in my Program.cs (.NET Core 6.0)
builder.Services.AddOpenIddict()
.AddCore(options =>
{
// Configure OpenIddict to use the EF Core stores/models.
options.UseEntityFrameworkCore()
.UseDbContext<OpenIDDBContext>();
})
.AddServer(options =>
{
options
.SetTokenEndpointUris("/token");
options
.AllowClientCredentialsFlow();
// Encryption and signing of tokens
options
.AddEphemeralEncryptionKey()
.AddEphemeralSigningKey()
.DisableAccessTokenEncryption();
// Register scopes (permissions)
//options.RegisterScopes("api");
// Register signing and encryption details
options.AddDevelopmentEncryptionCertificate()
.AddDevelopmentSigningCertificate();
// Register the ASP.NET Core host and configure the ASP.NET Core-specific options.
options
.UseAspNetCore()
.EnableTokenEndpointPassthrough()
.DisableTransportSecurityRequirement();
})
.AddValidation(options =>
{
// Import the configuration from the local OpenIddict server instance.
options.UseLocalServer();
// Register the ASP.NET Core host.
options.UseAspNetCore();
});
Can anyone please point out what needs to be corrected so that Token authentication works on Local IIS Server we well.
Thanks !