forked from CodeBeamOrg/UltimateAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHubLoginController.cs
More file actions
54 lines (46 loc) · 1.83 KB
/
HubLoginController.cs
File metadata and controls
54 lines (46 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using CodeBeam.UltimateAuth.Core.Abstractions;
using CodeBeam.UltimateAuth.Core.Domain;
using CodeBeam.UltimateAuth.Core.MultiTenancy;
using CodeBeam.UltimateAuth.Core.Options;
using CodeBeam.UltimateAuth.Server.Options;
using CodeBeam.UltimateAuth.Server.Stores;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
namespace CodeBeam.UltimateAuth.Sample.UAuthHub.Controllers;
[Route("uauthhub")]
[IgnoreAntiforgeryToken]
public sealed class HubLoginController : Controller
{
private readonly IAuthStore _authStore;
private readonly UAuthServerOptions _options;
private readonly IClock _clock;
public HubLoginController(IAuthStore authStore, IOptions<UAuthServerOptions> options, IClock clock)
{
_authStore = authStore;
_options = options.Value;
_clock = clock;
}
[HttpPost("login")]
[IgnoreAntiforgeryToken]
public async Task<IActionResult> BeginLogin(
[FromForm] string authorization_code,
[FromForm] string code_verifier,
[FromForm] UAuthClientProfile client_profile,
[FromForm] string? return_url)
{
var hubSessionId = HubSessionId.New();
var payload = new HubFlowPayload();
payload.Set("authorization_code", authorization_code);
payload.Set("code_verifier", code_verifier);
var artifact = new HubFlowArtifact(
hubSessionId: hubSessionId,
flowType: HubFlowType.Login,
clientProfile: client_profile,
tenant: TenantKeys.System,
returnUrl: return_url,
payload: payload,
expiresAt: _clock.UtcNow.Add(_options.Hub.FlowLifetime));
await _authStore.StoreAsync(new AuthArtifactKey(hubSessionId.Value), artifact, HttpContext.RequestAborted);
return Redirect($"{_options.Hub.LoginPath}?hub={hubSessionId.Value}");
}
}