C
C#•10mo ago
Ares

google authentication question

so i am trying to login to my app with google, and it always gives me error 500 whenever I do. I added the redirect uri to the google console already, yet it wont let me signin. it works fine locally in docker so not sure what the issue is.
No description
No description
No description
18 Replies
Ares
AresOP•10mo ago
and then the deployed app : https://realtime-poll.onrender.com
tera
tera•10mo ago
check your app logs
i like chatgpt
i like chatgpt•10mo ago
First try with http instead of https: and use redirecturl with a trailing /. In your case: https://realtime-poll.onrender.com/signin-google/ instead of https://realtime-poll.onrender.com/signin-google.
Ares
AresOP•10mo ago
ok i checked my app logs and it says:
info: Microsoft.AspNetCore.Authentication.Google.GoogleHandler[4]
Error from RemoteAuthentication: OAuth token endpoint failure: redirect_uri_mismatch;Description=Bad Request.
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HN1MLCDIBPSN", Request id "0HN1MLCDIBPSN:00000003": An unhandled exception was thrown by the application.
Microsoft.AspNetCore.Authentication.AuthenticationFailureException: An error was encountered while handling the remote login.
info: Microsoft.AspNetCore.Authentication.Google.GoogleHandler[4]
Error from RemoteAuthentication: OAuth token endpoint failure: redirect_uri_mismatch;Description=Bad Request.
fail: Microsoft.AspNetCore.Server.Kestrel[13]
Connection id "0HN1MLCDIBPSN", Request id "0HN1MLCDIBPSN:00000003": An unhandled exception was thrown by the application.
Microsoft.AspNetCore.Authentication.AuthenticationFailureException: An error was encountered while handling the remote login.
Ares
AresOP•10mo ago
doesnt let me add http as a redirect uri, it says
No description
Ares
AresOP•10mo ago
oh one sec
i like chatgpt
i like chatgpt•10mo ago
Is it in production?
Ares
AresOP•10mo ago
yes but changed it to testing but im not sure if that was good to do it allowed me to add the http but not sure if that was how i was supposed to do it
i like chatgpt
i like chatgpt•10mo ago
Does it work now with http? It is only for troubleshooting.
Ares
AresOP•10mo ago
yes it works now
i like chatgpt
i like chatgpt•10mo ago
It seems you have a problem with https certificate or forwarding issue.
Ares
AresOP•10mo ago
yeah im not sure why im not realy sure why it redirects me to http instead of https as the redirect uri .i thought maybe it was my program.cs configuration but im not really sure
i like chatgpt
i like chatgpt•10mo ago
Keep trying because you and I both have the same issue. 🙂 I am still figuring out what happens by reading many articles on the internet.
Ares
AresOP•10mo ago
oh ok
app.Use(
(context, next) =>
{
context.Request.Scheme = "https";
return next(context);
}
);
app.Use(
(context, next) =>
{
context.Request.Scheme = "https";
return next(context);
}
);
i tried something liek this and i was able to get to login but the login itself still didnt work i dont reallt know what any of this stuff means unfortunately im new to .net and i dont really understand all this http https ssl stuff tbh app.UseHttpsRedirection(); and apparently this line in program.cs should fix the issue but it doesnt hey i think i fixed it. all i did was added app.UseAuthentication(); to program.cs. in this order:
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
app.UseRouting();
app.UseAuthentication();
app.UseAuthorization();
i like chatgpt
i like chatgpt•10mo ago
In my simplest test project, I remove all of the following:
builder.Services.AddAuthentication();
builder.Services.AddAuthorization();
// ...
app.UseAuthentication();
app.UseAuthorization();
builder.Services.AddAuthentication();
builder.Services.AddAuthorization();
// ...
app.UseAuthentication();
app.UseAuthorization();
But I enable the following
builder.Services.Configure<ForwardedHeadersOptions>(
o => o.ForwardedHeaders = ForwardedHeaders.XForwardedProto);
// ...
app.UseForwardedHeaders();
builder.Services.Configure<ForwardedHeadersOptions>(
o => o.ForwardedHeaders = ForwardedHeaders.XForwardedProto);
// ...
app.UseForwardedHeaders();
and using var redirectUrl = "https://localhost:7000/signin-google/"; that matches exactly the settings I specified in Google's Cloud Console. Finally my endpoint app.MapGet("signin-google", ...); is successfully invoked by Google's OAuth redirection. 🙂 @Ares
Ares
AresOP•10mo ago
thats good. i dont really understand what most of that means but glad you were able to fix it lol. i also added /signin google to GCC, maybe thats what fixed it
i like chatgpt
i like chatgpt•10mo ago
It means the issue is only about forwarding header no matter we enable authentication/authorization middleware.
Ares
AresOP•10mo ago
im super late but thanks lol
Want results from more Discord servers?
Add your server