-
Notifications
You must be signed in to change notification settings - Fork 146
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
redirect_uri in redirects' targetUrl not returning https #436
Comments
Hey @tacman , isn't the target URL is something that should be specified on the third-party provider side? I.e. in the GitHub/Facebook/Google app configuration? To me it sounds like you specify redirect URL with |
I'll dig in some more to reproduce it. I'm just setting the path, but it looks like it should return https. Question: What do you use to test logging in with google? I can't put https://oauth-demo.wip in as the redirect URL, so I probably need to set up some sort of proxy that redirects to my local machine. |
Ngrok should help with forwarding a temporary real URL to your localhost app - that's good for debugging and development, but there're also many alternatives to ngrok over the internet. |
Thanks. No matter what I do, I can't get login with Google to work. Using ngrok, I get through authorizing my account, then when it redirects back, I get Error fetching OAuth credentials: "redirect_uri_mismatch". The ngrok logs
The PHP logs
Alas, I'm stuck and don't know how to debug this. It's not making it to "connect", as I have a dd() there, so it must be generating that error within a listener.
Thanks. |
I think I've figured it out. Related to symfony/symfony#37980. Once I added TRUSTED_PROXIES, not only did I get the debug toolbar but my redirect was correct and I logged in locally as expected! |
After an embarrassingly long time investigating, the issue is somewhere in here, AbstractProvider.php public function createProvider($class, array $options, ?string $redirectUri = null, array $redirectParams = [], array $collaborators = [])
{
if (null !== $redirectUri) {
$redirectUri = $this->generator
->generate($redirectUri, $redirectParams, UrlGeneratorInterface::ABSOLUTE_URL);
$options['redirectUri'] = $redirectUri;
} The generator at this point is CompiledUrlGenerator, which generates http rather than https. Any suggestions? |
My solution is to force https /**
* Creates a provider of the given class.
*
* @param string $class
*/
public function createProvider($class, array $options, ?string $redirectUri = null, array $redirectParams = [], array $collaborators = [])
{
if (null !== $redirectUri) {
$redirectUri = $this->generator
->generate($redirectUri, $redirectParams, UrlGeneratorInterface::ABSOLUTE_URL);
$redirectUri = str_replace('http:','https:', $redirectUri);
$options['redirectUri'] = $redirectUri;
}
return new $class($options, $collaborators);
} There's likely a better way, but I don't know what it is. |
After too many hours of hacking, I discovered that the redirect that comes back is sometimes using http, not https.
Curiously, for me it's happening on production, but not locally.
Here's my solution, but surely there's a better way.
The text was updated successfully, but these errors were encountered: