Initial commit

This commit is contained in:
2026-06-02 10:51:14 +02:00
committed by kawa
commit d19092c84e
182 changed files with 13757 additions and 0 deletions
+10
View File
@@ -0,0 +1,10 @@
namespace SharepointToolbox.Web.Services.OAuth;
public class AppRegistrationResult
{
public string ClientId { get; set; } = string.Empty;
public string DisplayName { get; set; } = string.Empty;
public string TenantId { get; set; } = string.Empty;
public string TenantUrl { get; set; } = string.Empty;
public string TenantName { get; set; } = string.Empty;
}
+13
View File
@@ -0,0 +1,13 @@
using SharepointToolbox.Web.Core.Models;
namespace SharepointToolbox.Web.Services.OAuth;
public interface IOAuthFlowCache
{
void StoreFlowState(string state, OAuthFlowState flowState);
OAuthFlowState? GetAndRemoveFlowState(string state);
void StoreTokens(string tokenKey, SessionTokens tokens);
SessionTokens? GetAndRemoveTokens(string tokenKey);
void StoreRegistrationResult(string key, AppRegistrationResult result);
AppRegistrationResult? GetAndRemoveRegistrationResult(string key);
}
+44
View File
@@ -0,0 +1,44 @@
using Microsoft.Extensions.Caching.Memory;
using SharepointToolbox.Web.Core.Models;
namespace SharepointToolbox.Web.Services.OAuth;
public class OAuthFlowCache : IOAuthFlowCache
{
private readonly IMemoryCache _cache;
public OAuthFlowCache(IMemoryCache cache) { _cache = cache; }
public void StoreFlowState(string state, OAuthFlowState flowState) =>
_cache.Set($"oauth_state_{state}", flowState, TimeSpan.FromMinutes(10));
public OAuthFlowState? GetAndRemoveFlowState(string state)
{
var key = $"oauth_state_{state}";
var value = _cache.Get<OAuthFlowState>(key);
if (value is not null) _cache.Remove(key);
return value;
}
public void StoreTokens(string tokenKey, SessionTokens tokens) =>
_cache.Set($"oauth_tokens_{tokenKey}", tokens, TimeSpan.FromMinutes(2));
public SessionTokens? GetAndRemoveTokens(string tokenKey)
{
var key = $"oauth_tokens_{tokenKey}";
var value = _cache.Get<SessionTokens>(key);
if (value is not null) _cache.Remove(key);
return value;
}
public void StoreRegistrationResult(string key, AppRegistrationResult result) =>
_cache.Set($"oauth_reg_{key}", result, TimeSpan.FromMinutes(5));
public AppRegistrationResult? GetAndRemoveRegistrationResult(string key)
{
var cacheKey = $"oauth_reg_{key}";
var value = _cache.Get<AppRegistrationResult>(cacheKey);
if (value is not null) _cache.Remove(cacheKey);
return value;
}
}
+16
View File
@@ -0,0 +1,16 @@
namespace SharepointToolbox.Web.Services.OAuth;
public class OAuthFlowState
{
public string CodeVerifier { get; set; } = string.Empty;
public string ProfileId { get; set; } = string.Empty;
public string TenantId { get; set; } = string.Empty;
public string ClientId { get; set; } = string.Empty;
public string SpHost { get; set; } = string.Empty;
public string ReturnUrl { get; set; } = "/";
// Registration flow only
public bool IsRegistration { get; set; }
public string TenantName { get; set; } = string.Empty;
public string TenantUrl { get; set; } = string.Empty;
}