-
-
Notifications
You must be signed in to change notification settings - Fork 528
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
Add a Sample where the Authorization Server and Resource Server are separate. #1340
Comments
https://github.com/openiddict/openiddict-samples#aspnet-core-samples |
Thanks for the quick response! |
I am having problems because I am trying to get this to work for a .NET Framework 4.6.1 API. I found another older issue with the same problem. openiddict/openiddict-samples#63 I am attempting to do the same thing. Except I'm using Client Credentials flow. |
If you need a hand, consider sponsoring the project and I'll make sure to point you in the right direction. |
Done! |
At first I was doing this from within my API Resource server:
It sounds like I can't do any of this with Owin, right? |
Some problem trying to pay for the sponsorship. Getting a 404 when trying to use PayPal. I made a direct payment instead. |
Thanks, much appreciated!
It should definitely work with OWIN. Do you use Web API 2 with the OWIN host? If so, did you decorate your API endpoints with If it still doesn't work, please post your logs. |
Yes, it's Web API 2.2 using Microsoft.AspNet.WebApi 5.2.7 which from what I found means Web API 2. I didn't decorate the API endpoint - I will try that! Thanks! |
To be sure I am making sense, I am getting a token from my Authorization server via Postman and then making a Postman request to my .NET Framework 4.6.1 Web API 2 project API. Is Client Credential flow even right in this case? |
Without knowing more about your scenario, it's hard to tell. What's sure is that the client credentials flow is suited for machine-to-machine scenarios (i.e when there's no user involved and the client application needs to access API resources on its own). |
Ok, that's what I want, M2M. Client credential flow seems correct. I am essentially trying to backport Zirku API 1 to ASP.NET Framework 4.6.1. I want to make sure I have configured things correctly in Startup.cs. I am starting over because my code is now a mess of things I've tried. |
Stupid question - how to enable logs? I don't see anything except some debug output. |
This is the code for Startup.cs in my Resource Server. The API I am hosting is called "scim". `using Autofac; [assembly: OwinStartup(typeof(SSHandlerServer.Startup))] namespace SSHandlerServer
}` |
I followed the instructions at https://documentation.openiddict.com/guide/getting-started.html to set up an ASP.NET Core Authorization Server I call "IdServer". This is the Startup.cs for IdServer now: ` namespace IdServer
} |
This is my Worker.cs for the Authorization server: using IdServer.Data; namespace IdServer
} |
OpenIddict uses the .NET Platform Extensions logging stack, so you can use any compatible listener and register it using the regular logging APIs: E.g with services.AddLogging(options => options.AddDebug()); |
I wouldn't recommend using both Autofac AND a custom middleware to manually create scopes using the MSFT DI container. I don't think this explains why things are not working (but logging will definitely tell you what's happening) but you'll surely want to remove the custom DI stuff and use Autofac. |
Yeah, there is a mix of Autofac because I was trying everything to work. I will clean that up. I set up logging for the Authorization Server (IdServer) and my Resource Server (SSHandlerServer) that hosts the API, thanks for that tip. |
I will review your post step-by-step to reconfigure things with AutoFac: https://kevinchalet.com/2020/03/03/adding-openiddict-3-0-to-an-owin-application/ |
I got logging working so that should help. Thanks. |
This is the Resource Server log when I start debugging. It's the only logging I get from the Resource server. OpenIddict.Validation.OpenIddictValidationDispatcher: Debug: The event OpenIddict.Validation.OpenIddictValidationEvents+ProcessRequestContext was successfully processed by OpenIddict.Validation.Owin.OpenIddictValidationOwinHandlers+InferIssuerFromHost. |
This is the code for my Resource Server now: `using Autofac; [assembly: OwinStartup(typeof(SSHandlerServer.Startup))] namespace SSHandlerServer
}` |
It's weird you're not getting more details from the logging stack, like the error/error description returned by OI.
Are you 100% sure you're correctly attaching the token to the HTTP request? |
OWIN/Katana itself doesn't use the .NET Platform Extensions logging stuff, you need to configure that separately: https://github.com/aspnet/AspNetKatana/wiki/Debugging Can you try attaching the token to the |
Can you please try with a simple Web API 2 controller like the one in the sample project, just to be sure it's not something affected by SCIM? |
Also, try putting the |
That helped! More Logging happening ... |
Yes, this is starting to work. OpenIddict.Server.OpenIddictServerDispatcher: Information: The introspection request was rejected because the application 'SSHandlerServer' was not allowed to use the introspection endpoint. |
Ok, so I recreated the application in the database with the right permissions. Now it says Information: The authentication demand was rejected because the token had no audience attached. I know what to do there I think. |
It works! |
Wow, thanks! I can't believe this is finally working. |
Good to hear (well, read 😄) that! 👏🏻 |
I am trying to figure out in ASP.NET Framework how to separate the Authorization Server and Resource Server. I want my Authorization Server to run on port https://localhost:5001 and authorize for apis hosted on another port. All the samples demo the resource server and authorization server as one thing. Is this a supported scenario?
The text was updated successfully, but these errors were encountered: