Disconnect(CancellationToken cancellationToken)
{
var ownerUserId = GetRequiredOwnerUserId();
await _graph.DisconnectAsync(ownerUserId, cancellationToken);
return NoContent();
}
private string GetRequiredOwnerUserId()
{
return User.FindFirstValue(ClaimTypes.NameIdentifier) ?? User.FindFirstValue("sub")
?? throw new InvalidOperationException("Authenticated user id is missing.");
}
private string GetRedirectUri()
{
return _externalOrigin.BuildPath("/api/microsoft-graph/oauth/callback");
}
private static string BuildPopupHtml(bool success, string message)
{
var escaped = System.Net.WebUtility.HtmlEncode(message);
var status = success ? "connected" : "error";
var title = success ? "Outlook connected" : "Outlook connection failed";
var serializedMessage = System.Text.Json.JsonSerializer.Serialize(message);
return $@"
Outlook connection
{title}
{escaped}
You can close this window.
";
}
}