In my MAUI application, I am using Web Authenticator to login with google. I am using .NET 8
asp.net core webapi project to handle it.
Application was working fine on the top domain https://example.com
. Issue is occured when I moved the application to sub domain https://api.example.com
.
Issue occur after we login into google account and the google redirects us to our application https://api.example.com/signin-google?.....
Error: api.example.com is currently unable to handle this request.
Code used in program.cs
:
builder.Services.AddAuthentication(o =>
{
o.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
})
.AddCookie()
.AddGoogle(g =>
{
g.ClientId = GoogleClientId;
g.ClientSecret = GoogleClientSecret;
g.SaveTokens = true; a.SaveTokens = true;
});
Code used on Controller
:
[HttpGet(ApiRoutes.MobileAuth.Google)]
public async Task Google()
{
string scheme = "Google";
var auth = await Request.HttpContext.AuthenticateAsync(scheme);
if (!auth.Succeeded
|| auth?.Principal == null
|| !auth.Principal.Identities.Any(id => id.IsAuthenticated)
|| string.IsNullOrEmpty(auth.Properties.GetTokenValue("access_token")))
{
await Request.HttpContext.ChallengeAsync(scheme);
}
else
{
var claims = auth.Principal.Identities.FirstOrDefault()?.Claims;
string access_token = auth?.Properties?.GetTokenValue("access_token") ?? string.Empty;
//other operations
var url = callbackScheme + "://#access_token=" + (access_token.Trim());
Request.HttpContext.Response.Redirect(url);
}
}
5