Initial commit
This commit is contained in:
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user