#oauth cleanup
This commit is contained in:
@@ -8,7 +8,7 @@ using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Hutopy.Web.Controllers;
|
||||
|
||||
public class GoogleController(IIdentityService identityService, IHttpClientFactory httpClientFactory) : Controller
|
||||
public class GoogleController(IIdentityService identityService, IHttpClientFactory httpClientFactory, IConfiguration configuration) : Controller
|
||||
{
|
||||
[HttpPost("/api/google/sign-in")]
|
||||
public async Task<IActionResult> SignIn([FromBody] GoogleSignInRequest request)
|
||||
@@ -41,7 +41,7 @@ public class GoogleController(IIdentityService identityService, IHttpClientFacto
|
||||
user = await identityService.FindUserByEmailAsync(email);
|
||||
}
|
||||
|
||||
if (user is null)
|
||||
if (user?.Id is null)
|
||||
{
|
||||
return BadRequest("Unable to find or create the user.");
|
||||
}
|
||||
@@ -58,7 +58,14 @@ public class GoogleController(IIdentityService identityService, IHttpClientFacto
|
||||
var claimsIdentity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme);
|
||||
await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));
|
||||
|
||||
var jwtToken = JwtTokenHelper.GenerateJwtToken("https://hutopy.com", "Hutopy", "V3J3bWFuUml3ZVpQbmxlWmZhWEo3ZkJSZ01YbHBwS24=", user.Id!);
|
||||
var issuer = configuration["Jwt:Issuer"] ??
|
||||
throw new ArgumentNullException("The Jwt issuer is missing.");
|
||||
var audience = configuration["Jwt:Audience"] ??
|
||||
throw new ArgumentNullException("The Jwt audience is missing.");
|
||||
var key = configuration["Jwt:Key"] ??
|
||||
throw new ArgumentNullException("The Jwt key is missing.");
|
||||
|
||||
var jwtToken = JwtTokenHelper.GenerateJwtToken(issuer, audience, key, user.Id);
|
||||
|
||||
return Ok(new { accessToken = jwtToken, email });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user