Hello, i'm doing .net web api and trying to implement google login and still getting 'redirect_uri_mismatch' error when trying to call the login from browser (just from url not yet from web application) and can't figured out of this shit... I'm googling about week and still without solution... and the example in documentation is not workingfor me...
I'm configuring google login in Program.cs:
NOTE: I have configured that all endpoints have "api" prefix (like https://localhost:1234/api/controller/endpoint)
public class Program
{
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
// ...
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
})
.AddCookie()
.AddGoogle(options =>
{
options.SignInScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.ClientId = "...";
options.ClientSecret = "...";
});
services.AddAuthorization();
services.AddOpenApi();
var app = builder.Build();
// ...
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization();
app.MapControllers();
app.Run();
}
}
This is my controller for login:
[ApiController]
[Route("auth/socials")]
public class AuthSocialsController : Controller
{
[HttpGet("google/login")]
public async void GoogleLogin()
{
await HttpContext.ChallengeAsync(GoogleDefaults.AuthenticationScheme);
}
[HttpGet("google/callback")]
public async Task<IActionResult> GoogleLoginCallback()
{
var result = await HttpContext.AuthenticateAsync(CookieAuthenticationDefaults.AuthenticationScheme);
//...
}
}
And this is my Google cloud login configuration:
- I also tryed the "https://localhost:7004" into JS origins but still nothing..
I would be very grateful for any help,
JD