Files
SharepointToolbox-Web/Components/Shared/SessionCredentialsModal.razor
T
2026-06-02 10:56:03 +02:00

79 lines
2.4 KiB
Plaintext

@inject ISessionCredentialStore CredStore
@inject IUserSessionService Session
@inject ISessionManager SessionManager
@inject NavigationManager Nav
@using SharepointToolbox.Web.Core.Models
@using SharepointToolbox.Web.Services.Session
@if (_visible)
{
<div class="modal-overlay">
<div class="modal-dialog">
<div class="modal-header">
<h3>Connect to Microsoft</h3>
<p class="text-muted">
Authenticate to access <strong>@Session.CurrentProfile?.Name</strong>.
Your session token is stored in your browser only — never saved to disk.
</p>
</div>
@if (!string.IsNullOrEmpty(_error))
{
<div class="alert alert-error">@_error</div>
}
<div class="flex-row mt-8">
<button class="btn btn-primary" @onclick="ConnectAsync" disabled="@_connecting">
@(_connecting ? "Redirecting…" : "Connect via Microsoft")
</button>
<button class="btn btn-secondary" @onclick="Cancel" disabled="@_connecting">Cancel</button>
</div>
<p class="text-muted" style="font-size:11px;margin-top:8px">
You will be redirected to Microsoft login. MFA is supported.
</p>
</div>
</div>
}
@code {
[Parameter] public EventCallback OnConnected { get; set; }
private bool _visible;
private bool _connecting;
private string _error = string.Empty;
public async Task ShowAsync()
{
_error = string.Empty;
_connecting = false;
_visible = true;
await InvokeAsync(StateHasChanged);
}
private async Task ConnectAsync()
{
var profile = Session.CurrentProfile;
if (profile is null) { _error = "No client profile selected."; return; }
_connecting = true;
_error = string.Empty;
// Clear any stale CSOM contexts
await SessionManager.ClearAllAsync();
var currentUrl = Nav.Uri;
var connectUrl = $"/connect/initiate?profileId={Uri.EscapeDataString(profile.Id)}" +
$"&returnUrl={Uri.EscapeDataString(currentUrl)}";
// Force full HTTP navigation to break out of the Blazor SignalR circuit
Nav.NavigateTo(connectUrl, forceLoad: true);
}
private void Cancel()
{
_visible = false;
_connecting = false;
}
}