public static SessionToken FromEncodedToken(byte[] encoded)
{
// Read the token
try
{
MemoryStream strm = new MemoryStream(encoded);
BinaryReader reader = new BinaryReader(strm);
int version = reader.ReadInt32();
if (version != CurrentVersion)
{
throw new NotSupportedException("Token version is not supported");
}
reader.ReadBytes(20); // Skip the nonce
int userId = reader.ReadInt32();
string email = reader.ReadString();
string displayName = reader.ReadString();
string[] roles = reader.ReadString().Split('|');
DateTime expires = new DateTime(reader.ReadInt64());
return new SessionToken(
new ReviewRPrincipal(
new ReviewRIdentity()
{
UserId = userId,
Email = email,
DisplayName = displayName,
Roles = new HashSet<string>(roles)
}), expires);
}
catch (NotSupportedException)
{
// Let the NSEx bubble up
throw;
}
catch (Exception ex)
{
throw new InvalidDataException("Error deserializing token", ex);
}
}