DocSpace-buildtools/common/ASC.FederatedLogin/Profile/LoginProfileExtensions.cs

50 lines
2.0 KiB
C#
Raw Normal View History

namespace ASC.FederatedLogin.Profile;
public static class LoginProfileExtensions
2019-06-06 13:34:46 +00:00
{
public static Uri AddProfile(this Uri uri, LoginProfile profile)
2019-06-06 13:34:46 +00:00
{
return profile.AppendProfile(uri);
}
public static Uri AddProfileSession(this Uri uri, LoginProfile profile, Microsoft.AspNetCore.Http.HttpContext context)
{
return profile.AppendSessionProfile(uri, context);
}
public static Uri AddProfileCache(this Uri uri, LoginProfile profile, IMemoryCache memoryCache)
{
return profile.AppendCacheProfile(uri, memoryCache);
}
public static LoginProfile GetProfile(this Uri uri, HttpContext context, IMemoryCache memoryCache, Signature signature, InstanceCrypto instanceCrypto)
{
var profile = new LoginProfile(signature, instanceCrypto);
var queryString = HttpUtility.ParseQueryString(uri.Query);
if (!string.IsNullOrEmpty(queryString[LoginProfile.QuerySessionParamName]) && context != null && context.Session != null)
2019-06-06 13:34:46 +00:00
{
return JsonConvert.DeserializeObject<LoginProfile>(context.Session.GetString(queryString[LoginProfile.QuerySessionParamName]));
2019-06-06 13:34:46 +00:00
}
if (!string.IsNullOrEmpty(queryString[LoginProfile.QueryParamName]))
2019-06-06 13:34:46 +00:00
{
profile.ParseFromUrl(context, uri, memoryCache);
return profile;
2019-06-06 13:34:46 +00:00
}
if (!string.IsNullOrEmpty(queryString[LoginProfile.QueryCacheParamName]))
2019-06-06 13:34:46 +00:00
{
return (LoginProfile)memoryCache.Get(queryString[LoginProfile.QuerySessionParamName]);
2019-06-06 13:34:46 +00:00
}
return null;
}
2019-06-06 13:34:46 +00:00
public static bool HasProfile(this Uri uri)
{
var queryString = HttpUtility.ParseQueryString(uri.Query);
return !string.IsNullOrEmpty(queryString[LoginProfile.QueryParamName])
|| !string.IsNullOrEmpty(queryString[LoginProfile.QuerySessionParamName])
|| !string.IsNullOrEmpty(queryString[LoginProfile.QueryCacheParamName]);
2019-06-06 13:34:46 +00:00
}
}