C
C#3mo ago
lumijiez

Implementing Google OAuth throws an error after logging in

I'm losing my mind over this, I'm sure it's a minor fix but I can't seem to get it working, I've setup the Google OAuth controller, and everything seems to be working at glance, the application builds, the url gets me to google, i can select my account, but once it tries to call the callback, it says the oauth state is missing or invalid https://github.com/lumijiez/raven/blob/dev/auth/server/Raven/Raven.Auth/Controllers/GoogleOAuthController.cs https://github.com/lumijiez/raven/blob/dev/auth/server/Raven/Raven.Auth/Startup.cs here are the relevant files
GitHub
raven/server/Raven/Raven.Auth/Controllers/GoogleOAuthController.cs ...
Contribute to lumijiez/raven development by creating an account on GitHub.
GitHub
raven/server/Raven/Raven.Auth/Startup.cs at dev/auth · lumijiez/raven
Contribute to lumijiez/raven development by creating an account on GitHub.
10 Replies
Marvin
Marvin3mo ago
if think instead of setting "options.CallbackPath = "/oauth/google/callback";" inside AddGoogle. Remove setting that CallbackPath. and just use the RedirectUri that u set in the AuthenticationProperties. It will then correctly first redirect to the internal path of default value of CallbackPath and then to your endpoint.
lumijiez
lumijiezOP3mo ago
that wont work because im not using the default google url, so i need to put it there, if i remove the callback path setting, google just shows a redirect mismatch
Marvin
Marvin3mo ago
Then you might need to check to do that properly because that setting is: CallbackPath is not supposed to refer to a controller, it refers to a unique path handled by the auth middleware (defaults to /signin-google). It will redirect back to your controller when it's done.
lumijiez
lumijiezOP3mo ago
ohh, i see then
public IActionResult Login()
{
var redirectUrl = Url.Action("Callback", "GoogleOAuth");
var properties = new AuthenticationProperties
{
RedirectUri = redirectUrl
};
return Challenge(properties, GoogleDefaults.AuthenticationScheme);
}
public IActionResult Login()
{
var redirectUrl = Url.Action("Callback", "GoogleOAuth");
var properties = new AuthenticationProperties
{
RedirectUri = redirectUrl
};
return Challenge(properties, GoogleDefaults.AuthenticationScheme);
}
so, it means this returns a wrong url if im getting a mismatch right?
Marvin
Marvin3mo ago
maybe you could rename your callback and keep the options.CallbackPath = "/oauth/google/callback"; in so the internal middleware catches /oauth/google/callback im sorry, im bad with terms let me rephrase
lumijiez
lumijiezOP3mo ago
yeah, i understood, i did that and it worked lol thank you SO MUCH
Marvin
Marvin3mo ago
ah ok
lumijiez
lumijiezOP3mo ago
i misunderstood what callbackpath did thank you, i hope you have a beautiful life
Marvin
Marvin3mo ago
yea, there are some issues opened about that too, so its not just you i think ahaha, and youre welcome!
lumijiez
lumijiezOP3mo ago
thank you once again
Want results from more Discord servers?
Add your server