Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with setting up a stand alone Resource Server #1359

Closed
mcalasa opened this issue Dec 2, 2021 · 16 comments
Closed

Issue with setting up a stand alone Resource Server #1359

mcalasa opened this issue Dec 2, 2021 · 16 comments

Comments

@mcalasa
Copy link

mcalasa commented Dec 2, 2021

Hello,
I'm trying to set up a standalone resource server that is exactly what is described here: #1340.
My resource server is an OWIN/ASP.NET 4.8 Web API 2 application that has a simple controller that will be the protected resource and will be using the Client Credentials flow. The project was created in Visual Studio using the ASP.NET Web Application (.NET Framework) template.

The issue I'm experiencing is when I make a request to the API using Postman I get the following error:


{
    "Message": "An error has occurred.",
    "ExceptionMessage": "No OWIN authentication manager is associated with the request.",
    "ExceptionType": "System.InvalidOperationException",
    "StackTrace": "   at System.Web.Http.HostAuthenticationFilter.GetAuthenticationManagerOrThrow(HttpRequestMessage request)\r\n   at System.Web.Http.HostAuthenticationFilter.<AuthenticateAsync>d__4.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Controllers.AuthenticationFilterResult.<ExecuteAsync>d__5.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at System.Web.Http.Dispatcher.HttpControllerDispatcher.<SendAsync>d__15.MoveNext()"
}

In this request I'm passing the Authorization header with the bearer token.

This is what I get from the logging after I made that request:

OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessRequestContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+InferIssuerFromHost.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessRequestContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+InferIssuerFromHost.

Here is the startup.cs code for the resource server:

using Autofac;
using Autofac.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Owin;
using Owin;

[assembly: OwinStartup(typeof(Sample.OpenIddict.ResourceServer.Example.Startup))]

namespace Sample.OpenIddict.ResourceServer.Example
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=316888
            var services = new ServiceCollection();
            services.AddLogging(logging =>
            {
                logging.AddDebug();
                logging.SetMinimumLevel(LogLevel.Trace);
            });

            // Register the OpenIddict validation components.
            services.AddOpenIddict()
                .AddValidation(options =>
                {
                    // Note: the validation handler uses OpenID Connect discovery
                    // to retrieve the address of the introspection endpoint.
                    options.SetIssuer("https://localhost:44300/");
                    options.AddAudiences("TestAPI");

                    // Configure the validation handler to use introspection and register the client
                    // credentials used when communicating with the remote introspection endpoint.
                    options.UseIntrospection()
                        .SetClientId("TestAPI")
                        .SetClientSecret("1cf0d681bc3c4e31a273b0203496983e");

                    // Register the System.Net.Http integration.
                    options.UseSystemNetHttp();

                    // Register the Owin host.
                    options.UseOwin();
                   
                });

            var builder = new ContainerBuilder();

            builder.Populate(services);
            var container = builder.Build();
            app.UseAutofacMiddleware(container);
            
        }
    }
}

This is the protected resource decorated with the HostAuthentication attribute

using OpenIddict.Validation.Owin;
using System.Collections.Generic;
using System.Web.Http;

namespace Sample.OpenIddict.ResourceServer.Example.Controllers
{
    [HostAuthentication(OpenIddictValidationOwinDefaults.AuthenticationType)]
    public class ValuesController : ApiController
    {
        // GET api/values
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }

        // GET api/values/5
        public string Get(int id)
        {
            return "value";
        }

        // POST api/values
        public void Post([FromBody] string value)
        {
        }

        // PUT api/values/5
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/values/5
        public void Delete(int id)
        {
        }
    }
}

In regards to the error "No OWIN authentication manager is associated with the request." I made sure that the Microsoft.Owin.Host.SystemWeb is installed.
Also made sure and that these two lines are not in the WebApiConfig.cs file:

config.SuppressDefaultHostAuthentication();
config.Filters.Add(new HostAuthenticationFilter(OAuthDefaults.AuthenticationType));

I've also read the article of adding openiddict to an OWIN application (https://kevinchalet.com/2020/03/03/adding-openiddict-3-0-to-an-owin-application/) and I think I have it set up correctly. It seems that I'm missing something else and if I can be pointed to the right direction that would be much appreciated.

Thank you

@kevinchalet
Copy link
Member

Hey @mcalasa,

Thanks for sponsoring the project! 👍🏻

I suspect the issue you're seeing is caused by the fact the request is handled by the Web API web host instead of the OWIN integration, which seems to be confirmed by the missing app.UseWebApi() line in your startup class. To fix that:

  1. Make sure your application doesn't reference the Web API web host package.
  2. Call app.UseWebApi() after registering the OpenIddict middleware. Here's an example with Autofac: https://github.com/openiddict/openiddict-samples/blob/dev/samples/Kalarba/Kalarba.Server/Startup.cs#L44-L45

@mcalasa
Copy link
Author

mcalasa commented Dec 2, 2021

No problem, glad to sponsor such a awesome project.

For line item 1, not sure if this is the correct way to remove the reference to the Web API web host but in the global.asax I commented out GlobalConfiguration.Configure(WebApiConfig.Register) as shown below:

 public class WebApiApplication : System.Web.HttpApplication
    {
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            //GlobalConfiguration.Configure(WebApiConfig.Register);
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);
        }
    }

For line item 2, I modified the startup.cs file in my Resource Server based on the Kalarba sample that you provided.

using System.Reflection;
using System.Web.Http;
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Autofac.Integration.WebApi;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Owin;
using OpenIddict.Server.Owin;
using OpenIddict.Validation.Owin;
using Owin;

[assembly: OwinStartup(typeof(Sample.OpenIddict.ResourceServer.Example.Startup))]

namespace Sample.OpenIddict.ResourceServer.Example
{
    public class Startup
    {
        public void Configuration(IAppBuilder app)
        {
            // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=316888
            var container = CreateContainer();
            
            // Register the Autofac scope injector middleware.
            app.UseAutofacLifetimeScopeInjector(container);

            // Register the two OpenIddict server/validation middleware.
            app.UseMiddlewareFromContainer<OpenIddictServerOwinMiddleware>();
            app.UseMiddlewareFromContainer<OpenIddictValidationOwinMiddleware>();

            var configuration = new HttpConfiguration
            {
                DependencyResolver = new AutofacWebApiDependencyResolver(container)
            };

            configuration.MapHttpAttributeRoutes();

            // Configure ASP.NET Web API to use token authentication.
            configuration.Filters.Add(new HostAuthenticationFilter(OpenIddictValidationOwinDefaults.AuthenticationType));

            // Register the Web API/Autofac integration middleware.
            app.UseAutofacWebApi(configuration);
            app.UseWebApi(configuration);

        }

        private static IContainer CreateContainer()
        {
            var services = new ServiceCollection();
            services.AddLogging(logging =>
            {
                logging.AddDebug();
                logging.SetMinimumLevel(LogLevel.Trace);
            });

            // Register the OpenIddict validation components.
            services.AddOpenIddict()
                .AddValidation(options =>
                {
                    // Note: the validation handler uses OpenID Connect discovery
                    // to retrieve the address of the introspection endpoint.
                    options.SetIssuer("https://localhost:44300/");
                    options.AddAudiences("TestAPI");

                    // Configure the validation handler to use introspection and register the client
                    // credentials used when communicating with the remote introspection endpoint.
                    options.UseIntrospection()
                        .SetClientId("TestAPI")
                        .SetClientSecret("1cf0d681bc3c4e31a273b0203496983e");

                    // Register the System.Net.Http integration.
                    options.UseSystemNetHttp();

                    // Register the Owin host.
                    options.UseOwin();

                });

            var builder = new ContainerBuilder();
            builder.Populate(services);
            builder.RegisterApiControllers(Assembly.GetExecutingAssembly());

            return builder.Build();
        }
    }
}

When I try to start the Resource Server I get this error.

The requested service 'OpenIddict.Server.Owin.OpenIddictServerOwinMiddleware' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.

[ComponentNotRegisteredException: The requested service 'OpenIddict.Server.Owin.OpenIddictServerOwinMiddleware' has not been registered. To avoid this exception, either register a component to provide the service, check for service registration using IsRegistered(), or use the ResolveOptional() method to resolve an optional dependency.]
   Autofac.ResolutionExtensions.ResolveService(IComponentContext context, Service service, IEnumerable`1 parameters) in /home/appveyor/projects/autofac/src/Autofac/ResolutionExtensions.cs:878
   Autofac.ResolutionExtensions.Resolve(IComponentContext context, IEnumerable`1 parameters) in /home/appveyor/projects/autofac/src/Autofac/ResolutionExtensions.cs:294
   Autofac.ResolutionExtensions.Resolve(IComponentContext context, Parameter[] parameters) in /home/appveyor/projects/autofac/src/Autofac/ResolutionExtensions.cs:311
   Autofac.Integration.Owin.AutofacMiddleware`1.Invoke(IOwinContext context) +128

[InvalidOperationException: The middleware type 'OpenIddict.Server.Owin.OpenIddictServerOwinMiddleware' was registered with the application using Autofac but that type was not able to be resolved from the lifetime scope. Check your container registrations to ensure that 'OpenIddict.Server.Owin.OpenIddictServerOwinMiddleware' is registered. See the inner exception for details on what failed during resolution.]
   Autofac.Integration.Owin.AutofacMiddleware`1.Invoke(IOwinContext context) +259
   Microsoft.Owin.Infrastructure.OwinMiddlewareTransition.Invoke(IDictionary`2 environment) +45
   Microsoft.Owin.Extensions.<>c__DisplayClass3_1.<.ctor>b__1() +33
   Owin.<<RegisterAutofacLifetimeScopeInjector>b__0>d.MoveNext() +291
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<RunApp>d__7.MoveNext() +179
   System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) +102
   System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) +64
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.<DoFinalWork>d__12.MoveNext() +180
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.StageAsyncResult.End(IAsyncResult ar) +69
   Microsoft.Owin.Host.SystemWeb.IntegratedPipeline.IntegratedPipelineContext.EndFinalWork(IAsyncResult ar) +64
   System.Web.AsyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +484
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +132
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +163

I'm beginning to think if there is something with this project template from Visual Studio that is causing this issue. Should this be a self-hosting Owin application instead?

Do apologize in advance if I'm missing something in registering the OpenIddict middleware, I'm just wrapping my head around how OWIN works due to an existing ASP.NET 4.8 project that I will have to convert to OWIN.

@kevinchalet
Copy link
Member

For line item 1, not sure if this is the correct way to remove the reference to the Web API web host but in the global.asax I commented out GlobalConfiguration.Configure(WebApiConfig.Register) as shown below:

It's correct. You'll probably want to go one step further and ensure this NuGet package is not referenced by your project: https://www.nuget.org/packages/Microsoft.AspNet.WebApi.WebHost/

I'm beginning to think if there is something with this project template from Visual Studio that is causing this issue. Should this be a self-hosting Owin application instead?

I think the issue is way more trivial. Since your API doesn't have the authorization server in the same project, OpenIddictServerOwinMiddleware is not registered and Autofac throws an exception. Remove this and it should disappear:

app.UseMiddlewareFromContainer<OpenIddictServerOwinMiddleware>();

@mcalasa
Copy link
Author

mcalasa commented Dec 3, 2021

Awesome, the site is up and running now once I commented out:

app.UseMiddlewareFromContainer<OpenIddictServerOwinMiddleware>();

I think this is close to working. When I make a request to the resource server to access the protected resource I get this error in Postman:

{
    "Message": "Authorization has been denied for this request."
}{
    "error": "server_error",
    "error_description": "This resource server is currently unavailable.",
    "error_uri": "https://documentation.openiddict.com/errors/ID2092"
}

I am passing the authorization header with the token in the request.

This is what I get in the logs after the request is made:

OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessRequestContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+InferIssuerFromHost.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+ExtractAccessTokenFromAuthorizationHeader.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+ExtractAccessTokenFromBodyForm.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+ExtractAccessTokenFromQueryString.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+ValidateToken.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+PrepareConfigurationRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+PrepareGetHttpRequest`1[[OpenIddict.Validation.OpenIddictValidationEvents+PrepareConfigurationRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+PrepareConfigurationRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+AttachQueryStringParameters`1[[OpenIddict.Validation.OpenIddictValidationEvents+PrepareConfigurationRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Information: Start processing HTTP request GET https://localhost:44300/.well-known/openid-configuration
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Trace: Request Headers:
Accept: application/json
Accept-Charset: utf-8
User-Agent: OpenIddict.Validation.SystemNetHttp/3.1.1.0

System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Information: Sending HTTP request GET https://localhost:44300/.well-known/openid-configuration
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Trace: Request Headers:
Accept: application/json
Accept-Charset: utf-8
User-Agent: OpenIddict.Validation.SystemNetHttp/3.1.1.0

System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Information: Received HTTP response after 363.4112ms - OK
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Trace: Response Headers:
Server: Microsoft-IIS/10.0
X-Powered-By: OrchardCore, ASP.NET
Date: Fri, 03 Dec 2021 00:35:59 GMT
Content-Length: 1249
Content-Type: application/json; charset=UTF-8

System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Information: End processing HTTP request after 403.0718ms - OK
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Trace: Response Headers:
Server: Microsoft-IIS/10.0
X-Powered-By: OrchardCore, ASP.NET
Date: Fri, 03 Dec 2021 00:35:59 GMT
Content-Length: 1249
Content-Type: application/json; charset=UTF-8

OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ApplyConfigurationRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+SendHttpRequest`1[[OpenIddict.Validation.OpenIddictValidationEvents+ApplyConfigurationRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ApplyConfigurationRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+DisposeHttpRequest`1[[OpenIddict.Validation.OpenIddictValidationEvents+ApplyConfigurationRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ExtractConfigurationResponseContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+ExtractJsonHttpResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+ExtractConfigurationResponseContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ExtractConfigurationResponseContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+DisposeHttpResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+ExtractConfigurationResponseContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+HandleConfigurationResponseContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+HandleErrorResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+HandleConfigurationResponseContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+HandleConfigurationResponseContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+Discovery+ValidateIssuer.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+HandleConfigurationResponseContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+Discovery+ExtractCryptographyEndpoint.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+HandleConfigurationResponseContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+Discovery+ExtractIntrospectionEndpoint.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+PrepareCryptographyRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+PrepareGetHttpRequest`1[[OpenIddict.Validation.OpenIddictValidationEvents+PrepareCryptographyRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+PrepareCryptographyRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+AttachQueryStringParameters`1[[OpenIddict.Validation.OpenIddictValidationEvents+PrepareCryptographyRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Information: Start processing HTTP request GET https://localhost:44300/.well-known/jwks
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Trace: Request Headers:
Accept: application/json
Accept-Charset: utf-8
User-Agent: OpenIddict.Validation.SystemNetHttp/3.1.1.0

System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Information: Sending HTTP request GET https://localhost:44300/.well-known/jwks
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Trace: Request Headers:
Accept: application/json
Accept-Charset: utf-8
User-Agent: OpenIddict.Validation.SystemNetHttp/3.1.1.0

System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Information: Received HTTP response after 185.8013ms - OK
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Trace: Response Headers:
Server: Microsoft-IIS/10.0
X-Powered-By: OrchardCore, ASP.NET
Date: Fri, 03 Dec 2021 00:35:59 GMT
Content-Length: 1559
Content-Type: application/json; charset=UTF-8

System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Information: End processing HTTP request after 196.3055ms - OK
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Trace: Response Headers:
Server: Microsoft-IIS/10.0
X-Powered-By: OrchardCore, ASP.NET
Date: Fri, 03 Dec 2021 00:35:59 GMT
Content-Length: 1559
Content-Type: application/json; charset=UTF-8

OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ApplyCryptographyRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+SendHttpRequest`1[[OpenIddict.Validation.OpenIddictValidationEvents+ApplyCryptographyRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ApplyCryptographyRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+DisposeHttpRequest`1[[OpenIddict.Validation.OpenIddictValidationEvents+ApplyCryptographyRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ExtractCryptographyResponseContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+ExtractJsonHttpResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+ExtractCryptographyResponseContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ExtractCryptographyResponseContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+DisposeHttpResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+ExtractCryptographyResponseContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+HandleCryptographyResponseContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+HandleErrorResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+HandleCryptographyResponseContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+HandleCryptographyResponseContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+Discovery+ExtractSigningKeys.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+IntrospectToken.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was marked as rejected by OpenIddict.Validation.OpenIddictValidationHandlers+IntrospectToken.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+AttachHostChallengeError.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+AttachDefaultChallengeError.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+AttachHttpResponseCode`1[[OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+AttachCacheControlHeader`1[[OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+AttachWwwAuthenticateHeader`1[[OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+ProcessChallengeErrorResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Information: The response was successfully returned as a JSON document: {
  "error": "server_error",
  "error_description": "This resource server is currently unavailable.",
  "error_uri": "https://documentation.openiddict.com/errors/ID2092"
}.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+ProcessJsonResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was marked as handled by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+ProcessJsonResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].

This is the latest update code for the protected resource:

using OpenIddict.Validation.Owin;
using System.Collections.Generic;
using System.Web.Http;

namespace Sample.OpenIddict.ResourceServer.Example.Controllers
{

    //[HostAuthentication(OpenIddictValidationOwinDefaults.AuthenticationType)]
    [RoutePrefix("api")]
    public class ValuesController : ApiController
    {
        [Authorize, HttpGet]
        [Route("values")]
        // GET api/values
        public IEnumerable<string> Get()
        {
            return new string[] { "value1", "value2" };
        }        
    }
}

Not sure if its a configuration issue on the Authorization Server which is Orchard Core with OpenId enabled.
Thank you again for your help and quick responses!

@mcalasa
Copy link
Author

mcalasa commented Dec 3, 2021

After doing a bit of research I think I figured out my issue with the error 'This resource server is currently unavailable.' and it may be that my Authorization Server (Orchard Core) does not have an introspection endpoint. I don't see any option to enable to enable that endpoint as well.
Would this assumption be correct?

@kevinchalet
Copy link
Member

kevinchalet commented Dec 3, 2021

Your understanding is 100% correct: it's not a feature currently offered by the OrchardCore OpenID module, so the introspection endpoint is not enabled and OpenIddict returns a generic error when it detects there's no endpoint in the discovery document it can use when validating tokens.

You have 3 options, depending on what you want to do:

  • You can switch to local validation instead of introspection.
  • You can use a standalone OpenIddict server instead of an OrchardCore-based deployment.
  • You can use OC's plugins to amend the OpenIddict server options that are not configurable using the UI. Here's how you could do with an inline plugin, defined from the main Startup:
public void ConfigureServices(IServiceCollection services)
{
    services.AddOrchardCms()
        .ConfigureServices(services =>
        {
            services.AddOpenIddict()
                .AddServer()
                .SetIntrospectionEndpointUris("/connect/introspect");
        }, order: 10000);
}

@kevinchalet
Copy link
Member

I opened OrchardCMS/OrchardCore#10803 to track potential improvements in OC.

@mcalasa
Copy link
Author

mcalasa commented Dec 4, 2021

Oh man that is pretty cool how you can plug that into Orchard Core. Thank you for submitting the improvement issue to Orchard Core, I'm going to keep my eye on it :-)

Ok, I went with option 3 since this would be perfect for my scenario. Adding the inline plugin I now get a different error message and this one caught my attention: "This client application is not allowed to use the introspection endpoint."
Tried looking this up and didn't find any good answers. I took a look at some samples but didn't seen anything that would assist in resolving this. Not sure if this is something that is set up somewhere in Orchard Core -> OpenId Connect -> Applications.

Here is the full log after the request was made to the resource server from Postman.

OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessRequestContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+InferIssuerFromHost.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+ExtractAccessTokenFromAuthorizationHeader.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+ExtractAccessTokenFromBodyForm.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+ExtractAccessTokenFromQueryString.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+ValidateToken.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+PrepareIntrospectionRequestContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+Introspection+AttachCredentials.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+PrepareIntrospectionRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+PreparePostHttpRequest`1[[OpenIddict.Validation.OpenIddictValidationEvents+PrepareIntrospectionRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+PrepareIntrospectionRequestContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+Introspection+AttachToken.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+PrepareIntrospectionRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+Introspection+AttachBasicAuthenticationCredentials.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+PrepareIntrospectionRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+AttachFormParameters`1[[OpenIddict.Validation.OpenIddictValidationEvents+PrepareIntrospectionRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Information: Start processing HTTP request POST https://localhost:44300/connect/introspect
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Trace: Request Headers:
Accept: application/json
Accept-Charset: utf-8
User-Agent: OpenIddict.Validation.SystemNetHttp/3.1.1.0
Content-Type: application/x-www-form-urlencoded

System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Information: Sending HTTP request POST https://localhost:44300/connect/introspect
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Trace: Request Headers:
Accept: application/json
Accept-Charset: utf-8
User-Agent: OpenIddict.Validation.SystemNetHttp/3.1.1.0
Content-Type: application/x-www-form-urlencoded

System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Information: Received HTTP response after 34.4824ms - BadRequest
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.ClientHandler: Trace: Response Headers:
Server: Microsoft-IIS/10.0
X-Powered-By: OrchardCore, ASP.NET
Date: Fri, 03 Dec 2021 17:56:12 GMT
Content-Length: 209
Content-Type: application/json; charset=UTF-8

System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Information: End processing HTTP request after 37.6947ms - BadRequest
System.Net.Http.HttpClient.OpenIddict.Validation.SystemNetHttp.LogicalHandler: Trace: Response Headers:
Server: Microsoft-IIS/10.0
X-Powered-By: OrchardCore, ASP.NET
Date: Fri, 03 Dec 2021 17:56:12 GMT
Content-Length: 209
Content-Type: application/json; charset=UTF-8

OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ApplyIntrospectionRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+SendHttpRequest`1[[OpenIddict.Validation.OpenIddictValidationEvents+ApplyIntrospectionRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ApplyIntrospectionRequestContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+DisposeHttpRequest`1[[OpenIddict.Validation.OpenIddictValidationEvents+ApplyIntrospectionRequestContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ExtractIntrospectionResponseContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+ExtractJsonHttpResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+ExtractIntrospectionResponseContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ExtractIntrospectionResponseContext was successfully processed by OpenIddict.Validation.SystemNetHttp.OpenIddictValidationSystemNetHttpHandlers+DisposeHttpResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+ExtractIntrospectionResponseContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+HandleIntrospectionResponseContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+HandleErrorResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+HandleIntrospectionResponseContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+HandleIntrospectionResponseContext was marked as rejected by OpenIddict.Validation.OpenIddictValidationHandlers+HandleErrorResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+HandleIntrospectionResponseContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: An error occurred while introspecting the token.

OpenIddict.Abstractions.OpenIddictExceptions+GenericException: An error occurred while handling the introspection response.
  Error: unauthorized_client
  Error description: This client application is not allowed to use the introspection endpoint.
  Error URI: https://documentation.openiddict.com/errors/ID2075
   at OpenIddict.Validation.OpenIddictValidationService.<>c__DisplayClass5_0.<<IntrospectTokenAsync>g__HandleIntrospectionResponseAsync|3>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at OpenIddict.Validation.OpenIddictValidationService.<IntrospectTokenAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at OpenIddict.Validation.OpenIddictValidationService.<IntrospectTokenAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at OpenIddict.Validation.OpenIddictValidationHandlers.IntrospectToken.<HandleAsync>d__5.MoveNext()
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+IntrospectToken.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessAuthenticationContext was marked as rejected by OpenIddict.Validation.OpenIddictValidationHandlers+IntrospectToken.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+AttachHostChallengeError.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.OpenIddictValidationHandlers+AttachDefaultChallengeError.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+AttachHttpResponseCode`1[[OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+AttachCacheControlHeader`1[[OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+AttachWwwAuthenticateHeader`1[[OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Information: The response was successfully returned as a challenge response: {
  "error": "invalid_token",
  "error_description": "The specified token is invalid.",
  "error_uri": "https://documentation.openiddict.com/errors/ID2004"
}.
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+ProcessChallengeErrorResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext was marked as handled by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+ProcessChallengeErrorResponse`1[[OpenIddict.Validation.OpenIddictValidationEvents+ProcessChallengeContext, OpenIddict.Validation, Version=3.1.1.0, Culture=neutral, PublicKeyToken=35a561290d20de2f]].
Microsoft.Extensions.Http.DefaultHttpClientFactory: Debug: HttpMessageHandler expired after 120000ms for client 'OpenIddict.Validation.SystemNetHttp'

@kevinchalet
Copy link
Member

My bad, I forgot to mention that you'll also need to update the client entry in the database to allow it to use the introspection endpoint. For that, you can either access the SQL database manually and add ept:introspection to the Permissions column (represented as a JSON array) or you can use IOpenIdApplicationManager to retrieve the application, add the introspection endpoint permission and save it, exactly like what OC does for other endpoints:

https://github.com/OrchardCMS/OrchardCore/blob/main/src/OrchardCore.Modules/OrchardCore.OpenId/Controllers/ApplicationController.cs#L322

@mcalasa
Copy link
Author

mcalasa commented Dec 4, 2021

Woo hoo! I added the permission using SQL and its working now!!!
Thank you so much for you help, this was pretty cool to set up and I will play around with the other options you provided which was in regards to setting up the introspection endpoint.

Man OpenIddict implementation is just missing a few pieces on the GUI side in OC but it's there.

Thank you again!

@kevinchalet
Copy link
Member

Glad you like it! It's indeed still a bit rough but I hope either the OC folks or I will be able to give it more love at some point 😄

@mcalasa
Copy link
Author

mcalasa commented Dec 7, 2021

I would be willing to do some work on this since I may have other use cases in implementing other flows besides client credentials.

@abbasl7

This comment was marked as off-topic.

@mcalasa
Copy link
Author

mcalasa commented May 1, 2022

@kevinchalet I finally had the time to add the introspection permission endpoint into my orchard core using IOpenIdApplicationManager that you commented on here: #1359 (comment) and it was very straight forward. I think I'm going to add the revocation endpoint permission and give that a test drive as well. So cool! I'm going to submit a PR to Orchard Core for this when I'm done with everything. I'll be sure to discuss with the OC team beforehand of course :-) OrchardCMS/OrchardCore#10803 (comment)

Thank you again for your guidance on this.

@kevinchalet
Copy link
Member

@mcalasa awesome! ❤️

Let me know if you need help for the OC PR 😃

@mcalasa
Copy link
Author

mcalasa commented May 3, 2022

@kevinchalet Will do. If I have any question I'll ask it here: OrchardCMS/OrchardCore#10803 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants