Add frontend login
This commit is contained in:
parent
9af64e859a
commit
cb43207502
@ -1,5 +1,7 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.AspNetCore.Authentication;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Todo.Core.Interfaces.Persistence;
|
||||
|
||||
@ -26,6 +28,35 @@ namespace Todo.Api.Controllers
|
||||
return Ok(user);
|
||||
}
|
||||
|
||||
[HttpGet("login")]
|
||||
public async Task<IActionResult> Login([FromQuery] string returnUrl)
|
||||
{
|
||||
var props = new AuthenticationProperties
|
||||
{
|
||||
RedirectUri = Url.Action(nameof(Callback)),
|
||||
Items =
|
||||
{
|
||||
{"returnUrl", returnUrl}
|
||||
}
|
||||
};
|
||||
return Challenge(props);
|
||||
}
|
||||
|
||||
[HttpGet]
|
||||
public async Task<IActionResult> Callback()
|
||||
{
|
||||
// read external identity from the temporary cookie
|
||||
var result =
|
||||
await HttpContext.AuthenticateAsync("oidc");
|
||||
if (result?.Succeeded != true)
|
||||
{
|
||||
throw new Exception("External authentication error");
|
||||
}
|
||||
|
||||
var returnUrl = result.Properties?.Items["returnUrl"] ?? "~/";
|
||||
return Redirect(returnUrl);
|
||||
}
|
||||
|
||||
public record RegisterUserRequest
|
||||
{
|
||||
[Required] public string Email { get; init; }
|
||||
|
@ -1,10 +1,12 @@
|
||||
using System.Text.Json;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Todo.Api.Hubs.Models;
|
||||
using Todo.Core.Interfaces.Persistence;
|
||||
|
||||
namespace Todo.Api.Hubs
|
||||
{
|
||||
[Authorize]
|
||||
public class TodoHub : Hub
|
||||
{
|
||||
private readonly ITodoRepository _todoRepository;
|
||||
|
@ -24,7 +24,7 @@
|
||||
"MONGODB__Port": "27017",
|
||||
"GITEA__Url": "https://git.front.kjuulh.io",
|
||||
"GITEA__ClientId": "6982ef4f-cfc1-431c-a442-fad98355a059",
|
||||
"GITEA__": "stabKPEZ6di0VfPjYT4rb0jRGLA2gPSd2NEkGoBi0xLO"
|
||||
"GITEA__ClientSecret": "hXUrUz5xPhC7IE3dQKft9lHboBEwhNC8yFjSzKgF9Nyr"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.IdentityModel.Protocols.OpenIdConnect;
|
||||
|
||||
namespace Todo.Infrastructure;
|
||||
|
||||
|
@ -70,6 +70,8 @@ export const SocketProvider: FC = (props) => {
|
||||
|
||||
connection.start().then(() => {
|
||||
setConn(connection);
|
||||
}).catch(e => {
|
||||
window.location.href = `${serverUrl}/api/auth/login?returnUrl=${window.location.href}`
|
||||
});
|
||||
}, []);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user