Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
ADFS - Custom Store - CustomStringTransformAttributeStore
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.IdentityServer.ClaimsPolicy.Engine.AttributeStore;
using System.IdentityModel;
namespace CustomStringTransformAttributeStore
{
public class StringTransform : IAttributeStore
{
public IAsyncResult BeginExecuteQuery(string query, string[] parameters, AsyncCallback callback, object state)
{
if (String.IsNullOrEmpty(query))
{
throw new AttributeStoreQueryFormatException("Error : No query has been sent.");
}
if (null == parameters)
{
throw new AttributeStoreQueryFormatException("Error : No query parameter has been sent.");
}
string[][] output;
switch (query)
{
case "Base64ToGuid":
output = new string[parameters.Length][];
for (int i = 0; i < parameters.Length; i++)
{
if (!string.IsNullOrEmpty(parameters[i]))
{
output[i] = new string[1] { ConvertBase64ToGuid(parameters[i]) };
}
}
break;
default:
throw new AttributeStoreQueryFormatException(String.Format("The case called \"{0}\" is not supported.", query));
}
TypedAsyncResult<string[][]> asyncResult = new TypedAsyncResult<string[][]>(callback, state);
asyncResult.Complete(output, true);
return asyncResult;
}
public string[][] EndExecuteQuery(IAsyncResult result)
{
return TypedAsyncResult<string[][]>.End(result);
}
public void Initialize(Dictionary<string, string> config)
{
}
static private string ConvertBase64ToGuid(string myData)
{
byte[] encodeAsBytes = System.Convert.FromBase64String(myData);
string returnValue = new Guid(encodeAsBytes).ToString();
return returnValue;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.