Umbraco-CMS: Umbraco 14 - "The specified 'redirect_uri' is not valid for this client application." error when trying to login after a certain time period
Which Umbraco version are you using? (Please write the exact version, example: 10.1.0)
14.0.0
Bug summary
Getting an error:invalid_request after leaving an Umbraco site running for a while when trying to login. Error appears for any login method (local and SSO).
Specifics
Might be related to: https://github.com/umbraco/Umbraco-CMS/issues/16179; but I am not visiting the site behind a proxy.
Error image:
Steps to reproduce
It appears to happen randomly after leaving the website running after a while.
Try to login after an unspecified amount of time.
Expected result / actual result
Expecting to be able to login, actual is error returned in json format.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 1
- Comments: 31 (1 by maintainers)
Try set the “BackOfficeHost” and “UmbracoApplicationUrl” - We do not experience it after those two where set 😃
@dutchbreeze
So basically, if you put this in your startup.cs, you’re able to use a custom OpenIddictApplicationManager
Just make sure to place it before services.AddUmbraco()
I also see in the PR that I added these two lines in the startup’s configure:
I don’t remember if they truly had an impact.
And then the custom manager is pretty simple, check if the link is localhost or your dev environment and return true.
I also noticed that I let this part in the appsettings while looking for a solution for our local and dev appsettings I don’t know if they’re absolutely necessary, but I didn’t feel like wasting more time testing it out.
Obviously this will be taken out when we deploy in production. I strongly suggest everyone does the same. Also a good idea to have additional security measures in place.
After some more testing seems like the trigger wasn’t enough and I needed to add a job that runs every x time and run stored procudure with the follwing query for my dev env : (for every DB i put all domain accessing that DB, you can add as many urls to the array’s)
This issue has been mentioned on Umbraco community forum. There might be relevant details there:
https://forum.umbraco.com/t/publishing-site-on-aws-fargate/3668/4
@akarkaselis Just implemented this one, and at first glance it seems to work! Great! Thanks again for sharing!
Just to add up, I dont think these do anything: application.UseAuthorization(); application.UseCertificateForwarding();
I’ll let you know if I find anything while testing!
@akarkaselis I did not have the change to test, but will in the next couple of days. I’ll let you know the outcome. Thanks a lot for sharing!
I just decided to override the validation for local and dev environments until the site is in production. It’s been a real headache having to restart the site every time we wanted to access the backoffice from localhost or dev. With 2-3 devs working on the site, it was downright impossible.
If you inherit from "OpenIddictApplicationManager < OpenIddictEntityFrameworkCoreApplication > " you can override the “ValidateRedirectUriAsync” (and “ValidatePostLogoutRedirectUriAsync”), check the environment and simply return true.
Obviously, this needs to be taken out when the site will go into production.
@Strike3Digital It seems that a reboot does affect the database. The redirect url seems to be reset after a reboot. However, this is our opinion at first glance and is not thoroughly tested.
Yes, from the looks of it the error message occurs right when the value gets changed in the
umbracoOpenIddictApplicationstable.Thank you for looking into it @dutchbreeze!
Hi @jovanzlatanovic , thanks a lot for the substantiation. Also good pointing out that table, I was still in the assumption that the openid connect options are used for the redirect url (callbackpath).
At first glance it seems that the plain Umbraco login is also using the value from the umbracoOpenIddictApplications table. I conclude this from the fact that the error messages are occurring at the same pace. Can you acknowledge that?
Keep in mind that these conclusions are the result of a very short survey after your post.
Thanks again!
Hi @dutchbreeze, it would be in the
umbracoOpenIddictApplicationstable.Running an environment with a certain database sets the correct RedirectUris value.
After I try to run a different environment (on a different URL) the row with the
umbraco-back-officevalue in the table gets theRedirectUrisoverwritten with the different environment.I believe the reason sites work again after restarting is due to the fact when we run an environment again the value will get overwritten again.
And the “random amount of time” which is happening at which the sites break again is due to the fact it depends on when the other site using the same database gets run again.
Hope this helps with the investigation!
Hi @jovanzlatanovic, thank you for your message. We are not using appsettings.Release.json. We use config transformation during deployment.
Our situation is that the site works fine for a while and all of a sudden the issue pops up. Only way to solve it is to restart.
Hi all, we are still seeing this error even though we’ve set both BackOfficeHost and UmbracoApplicationUrl. We are running the latest 14.3.0