Skip to content

Instantly share code, notes, and snippets.

@lstyles
Last active December 27, 2018 23:09
Show Gist options
  • Select an option

  • Save lstyles/6d3a6197435ec292fb59952d09255e79 to your computer and use it in GitHub Desktop.

Select an option

Save lstyles/6d3a6197435ec292fb59952d09255e79 to your computer and use it in GitHub Desktop.
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
namespace Infrastructure.Security
{
/// <summary>
/// SSO State used to pass data through the SSO callback
/// </summary>
/// <seealso cref="System.IEquatable{Infrastructure.Security.SSOState}" />
public class SSOState : IEquatable<SSOState>
{
/// <summary>
/// Initializes a new instance of the <see cref="SSOState"/> class.
/// </summary>
public SSOState()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="SSOState"/> class.
/// </summary>
/// <param name="state">The state.</param>
public SSOState(string state)
{
byte[] bytes = Convert.FromBase64String(state);
var decodedState = Encoding.UTF8.GetString(bytes);
var deserialized = JsonConvert.DeserializeObject<SSOState>(decodedState);
this.StateId = deserialized.StateId;
this.RedirectUrl = deserialized.RedirectUrl;
}
/// <summary>
/// Gets or sets the state identifier.
/// </summary>
/// <value>
/// The state identifier.
/// </value>
public Guid StateId { get; set; }
/// <summary>
/// Gets or sets the redirect URL.
/// </summary>
/// <value>
/// The redirect URL.
/// </value>
public string RedirectUrl { get; set; }
/// <summary>
/// Converts to string.
/// </summary>
/// <returns>
/// A <see cref="System.String" /> that represents this instance.
/// </returns>
public override string ToString()
{
var result = JsonConvert.SerializeObject(this);
return Convert.ToBase64String(Encoding.UTF8.GetBytes(result));
}
/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// true if the current object is equal to the <paramref name="other">other</paramref> parameter; otherwise, false.
/// </returns>
public bool Equals(SSOState other)
{
if (other == null)
return false;
if (StateId != other.StateId || RedirectUrl != other.RedirectUrl)
return false;
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment