MVC Client unauthorized_client Invalid redirect_uri
This was a issue I had for over a day. It's a result from following the documentation from the following link. http://docs.identityserver.io/en/latest/topics/signin.html
Here is the relevant portion of the log. [ERR] Invalid redirect_uri: http://localhost/identitycore/signin-oidc {"ClientId":"AppClientId","ClientName":"App Core Client Client","RedirectUri":null,"AllowedRedirectUris":["http://localhost/Core"],
Nothing in the documentation states where or how to define a redirect Uri on the mvc client app. However, remembering the headache it was with IDS 3 and poor documentation, I went back to some old notes. Then I found an issues on SO.
.AddOpenIdConnect("oidc", options =>
{
options.Authority = "http://localhost/identitycore";
options.RequireHttpsMetadata = false;
options.ClientId = "AppClientId";
options.ClientSecret = "secret";
options.ResponseType = "code";
options.SaveTokens = true;
// This must match the redirect URI in the client
//https://stackoverflow.com/questions/35976870/how-to-set-redirect-uri-parameter-on-openidconnectoptions-for-asp-net-core#
options.Events.OnRedirectToIdentityProvider = async n =>
{
n.ProtocolMessage.RedirectUri = "http://localhost/identitycore/signin-oidc";
await Task.FromResult(0);
};
I'm creating this issue for 2 reasons. Hopefully create something others can find a lot quicker and not waste as much time. 2 to make sure this the correct way to resolve this problem. I did submit the above as an edit to the documentation page. PLEASE consider keeping the documentation up to date. If resources are not available, MS is linking this product in their documentation. Please consider asking them to help maintain the documentation to the latest versions of asp.net core and your product.
As an update, I can get to the login page but if I try to login, I either get redirected and the browser hangs so still in the dark what to do or where the correct documentation is. I would say what seeing now would have to be a bug.
The redirect I changed above back to http://localhost/yourapp/signin-oidc Have no idea what this is. If I just put it back to http://localhost/yourapp then it's a constant redirect back to the login page. Using the signin-oidc, constant look until the browser times out. All of this is simply trying to follow the documentation I referenced and using the InMemory template. For whatever reason, in all the troubleshooting, now I'm seeing the login page even without defining a redirect on the MVC client application. However, after logging in, gets stuck in an infinite loop.
You set the redirect URI in MVC's OpenID Connect handler using the CallbackPath property - and it defaults to /signin-oidc.
As an update, I can get to the login page but if I try to login, I either get redirected and the browser hangs so still in the dark what to do or where the correct documentation is. I would say what seeing now would have to be a bug.
The redirect I changed above back to http://localhost/yourapp/signin-oidc Have no idea what this is. If I just put it back to http://localhost/yourapp then it's a constant redirect back to the login page. Using the signin-oidc, constant look until the browser times out. All of this is simply trying to follow the documentation I referenced and using the InMemory template. For whatever reason, in all the troubleshooting, now I'm seeing the login page even without defining a redirect on the MVC client application. However, after logging in, gets stuck in an infinite loop.
BTW I have seen the infinity loop happen if you use HTTP and not HTTPS scheme
Thank you, that’s what I’m working on next. I should say I’m using IIS for this an not IIS Express.
From: morrisond91 [mailto:[email protected]] Sent: Friday, January 31, 2020 4:39 AM To: IdentityServer/IdentityServer4 [email protected] Cc: kkfrosty [email protected]; Author [email protected] Subject: Re: [IdentityServer/IdentityServer4] MVC Client unauthorized_client Invalid redirect_uri (#4032)
As an update, I can get to the login page but if I try to login, I either get redirected and the browser hangs so still in the dark what to do or where the correct documentation is. I would say what seeing now would have to be a bug.
The redirect I changed above back to http://localhost/yourapp/signin-oidc Have no idea what this is. If I just put it back to http://localhost/yourapp then it's a constant redirect back to the login page. Using the signin-oidc, constant look until the browser times out. All of this is simply trying to follow the documentation I referenced and using the InMemory template. For whatever reason, in all the troubleshooting, now I'm seeing the login page even without defining a redirect on the MVC client application. However, after logging in, gets stuck in an infinite loop.
BTW I have seen the infinity loop happen if you use HTTP and not HTTPS scheme
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/IdentityServer/IdentityServer4/issues/4032?email_source=notifications&email_token=ACTHITLZI6UWJZELX6UQH2TRAPWT3A5CNFSM4KNY5AQKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKOCTLI#issuecomment-580659629, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACTHITNBOJ5M4OEOMTTDVEDRAPWT3ANCNFSM4KNY5AQA.
BTW another thing i have noticed is that your redirect URI should not have a trailing slash. or it will be deemed invalid. I had this issue upgrading from .net core 2.2 to 3.1 which subsequently updated id srv nugets so i got all the new features and enhancements and there was a change to URI validation.
Cheers, Dave
Dave, I appreciate the input. A trailing slash results in a Invalid redirect Uri which was the first issue tackled. The documentation has to be better, I'm on and off over a week just trying to do something as simple as get an the server up working without issues, and a simple authentication with an MVC client, all while just trying to follow the documentation for it.
Update, I'm trying to do this in 2 projects. The documentation is so lacking, I had to go back to just a pure template while trying to work on a new project which I have no interest in CLI which is another pet peeve. But regardless, in the template solution using IISExpress, going back and enabling SSL and using https in the redirect within the MVC Client setup, the infinite loop appears to have gone away and the sample works. However, in my IIS solution, it didn't resolve the problem. However, in trying to weed through the disparate documentation along with the core documenation, we have a custom authentication database and need to use our own custom user. In going through and commenting out lines of code one by one, this line of code seems to have stopped the infinite loop. Now I just get an HTTP 500 I'm troubleshooting now.
services.AddDefaultIdentity
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Questions are community supported only and the authors/maintainers may or may not have time to reply. If you or your company would like commercial support, please see here for more information.
I'm still struggling with this. The last changes just got it a step further but now weeks after hassling with this, still back to what looks like a signin-oidc redirect. What's odd, is the code in the Identity Server isn't being called after the first time. THe question, how do we enable tracing or any type of debugging to try and figure out this problem. This is beyond frustrating. Thanks
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Questions are community supported only and the authors/maintainers may or may not have time to reply. If you or your company would like commercial support, please see here for more information.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.