I want to build a web only login with Google in ASP.NET Core Razor pages.
After user confirm login, if successful website will send request to get user public information from there gmail to google then compare it with website database by GoogleID. If user is already in database, website will direct them to home page, else direct them to register page to fill more information.
It work successful in localhost but when I deploying my web with free somee hosting. When login with google it say:
enter image description here
My authorized redirect URIs : http://www.fbittut.somee.com/signin-google and http://fbittut.somee.com/signin-google
Here is my code – Startup.cs
:
services.AddRazorPages()
.AddRazorPagesOptions(options =>
{
options.Conventions.AuthorizePage("/LoginPage/Login");
});
services.AddAuthentication(options =>
{
options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = GoogleDefaults.AuthenticationScheme;
})
.AddCookie()
.AddGoogle(GoogleDefaults.AuthenticationScheme, options =>
{
options.ClientId = Configuration["Authentication:Google:ClientId"];
options.ClientSecret = Configuration["Authentication:Google:ClientSecret"];
options.Scope.Add("https://www.googleapis.com/auth/userinfo.email");
options.Scope.Add("https://www.googleapis.com/auth/userinfo.profile");
});
Google login:
public class GoogleModel : PageModel
{
public IActionResult OnGet() => Challenge(new AuthenticationProperties { RedirectUri = Url.Page("/LoginPage/Login") }, "Google");
}
LoginPage:
public async Task<IActionResult> OnGetAsync(string remoteError = null)
{
if (remoteError != null)
{
// Handle error
return RedirectToPage("/LoginPage/Google");
}
else
{
Account account = _context.Accounts.FirstOrDefault(a => a.GoogleId == User.FindFirst("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier").Value);
{
//logic
}
}
return RedirectToPage("/Index");
}
I try to find solution but there is no one code like this way