/// <summary>
 /// Registra o token da resposta informada.
 /// </summary>
 /// <param name="response"></param>
 /// <param name="token">Token que será registrado.</param>
 public static void RegisterToken(System.ServiceModel.Web.OutgoingWebResponseContext response, string token)
 {
     if (response == null)
     {
         return;
     }
     response.Headers.Add(SecurityTokenMessageInspector.TokenHeaderName, token);
     response.Headers.Add(System.Net.HttpResponseHeader.SetCookie, string.Format("{0}={1}", SecurityTokenMessageInspector.TokenHeaderName, token));
 }
        /// <summary>
        /// Registra o token da resposta informada.
        /// </summary>
        /// <param name="response"></param>
        public static void RegisterToken(System.ServiceModel.Web.OutgoingWebResponseContext response)
        {
            if (response == null)
            {
                return;
            }
            var identity = Colosoft.Security.UserContext.Current.Principal.Identity as Colosoft.Security.Principal.DefaultIdentity;

            if (identity != null)
            {
                if (identity.IsAuthenticated && string.IsNullOrEmpty(identity.Token))
                {
                    throw new InvalidOperationException("Identity token is empty.");
                }
                RegisterToken(response, identity.Token);
            }
        }