Created
October 1, 2015 12:04
-
-
Save FlorianAlikoff/6288eb7b88df542d71b8 to your computer and use it in GitHub Desktop.
ADFS - Custom Store - CustomStringTransformAttributeStore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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