I have an asp net core + angular application with Google OAuth support. Google OAuth works perfectly locally, but when I deploy it to heroku and try to log in,I get
"Error 400: redirect_uri_mismatch": If you’re the app developer, make sure that these request details comply with Google policies. redirect_uri: https://boost-project.herokuapp.com/signin-google
My Startup.cs code:
services.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
.AddGoogle(options =>
{
var googleAuthNSection = configuration.GetSection("Google");
options.ClientId = googleAuthNSection["ClientId"];
options.ClientSecret = googleAuthNSection["ClientSecret"];
options.SignInScheme = IdentityConstants.ExternalScheme;
})
My controller code:
[ApiController]
[Route("api/[Controller]")]
public class AccountController : ControllerBase
{
[HttpGet("signin-google")]
public IActionResult GoogleLogin()
{
return OAuthLogin("Google");
}
private IActionResult OAuthLogin(string providerName)
{
// actually boost-project.herokuapp.com for run on heroku
var host = _configuration["Host"];
var redirectUrl = Url.Action("OAuthResponse", "Account", null, "https", host).ToLower();
var properties = _signInManager.ConfigureExternalAuthenticationProperties(providerName, redirectUrl);
return new ChallengeResult(providerName, properties);
}
[HttpGet("oauth-response")]
public async Task<IActionResult> OAuthResponse()
{
var info = await _signInManager.GetExternalLoginInfoAsync();
if (info == null)
return BadRequest();
var result = await _signInManager.ExternalLoginSignInAsync(info.LoginProvider, info.ProviderKey, false);
// redirect to main page angular app
if (result.Succeeded)
return Redirect(_clientUrlOptions.MainPageUrl);
var user = new AppUser
{
Email = info.Principal.FindFirst(ClaimTypes.Email).Value,
UserName = info.Principal.FindFirst(ClaimTypes.Email).Value
};
var identResult = await _userManager.CreateAsync(user);
if (identResult.Succeeded)
{
identResult = await _userManager.AddLoginAsync(user, info);
if (identResult.Succeeded)
{
await _signInManager.SignInAsync(user, false);
// redirect to main page angular app
return Redirect(_clientUrlOptions.MainPageUrl);
}
}
return BadRequest();
}
}
I've double checked my authorized redirect URIs, it's ok. Authorized redirect URIs
Redirect uri from error message are pretty match that i've point in my authorizred uri in google console cloud Google signin error
I am also verified my domain Domain verification
Any type of support/help is appreciated
Thanks