Пример #1
0
        /// <summary>
        /// Converts a v5 ticket to  v3 ticket
        /// </summary>
        /// <param name="ticket"></param>
        /// <returns></returns>
        public static OwinAuthenticationTicket Convert(AuthenticationTicket ticket)
        {
            var newTicket = new OwinAuthenticationTicket(
                GenerateClaimsIdentity(ticket.Principal), ticket.Properties);

            return(newTicket);
        }
Пример #2
0
        /// <summary>
        /// Converts a v3 ticket to a v5.
        /// </summary>
        public static AuthenticationTicket Convert(OwinAuthenticationTicket ticket, string authScheme)
        {
            var newTicket = new AuthenticationTicket(new ClaimsPrincipal(ticket.Identity),
                                                     ticket.Properties, authScheme);

            return(newTicket);
        }
Пример #3
0
        /// <summary>
        /// Serializes, encrypts and encodes an AuthenticationTicket
        /// created by OWIN's cookie authentication system.
        /// </summary>
        /// <param name="ticket">The v3 AuthenticationTicket</param>
        /// <param name="decryptionKey">The machineKey decryptionKey found in your web.config</param>
        /// <param name="validationKey">The machineKey validationKey found in your web.config</param>
        /// <param name="decryptionAlgorithm">The machineKey decryptionAlgorithm found in your web.config (Auto == AES)</param>
        /// <param name="validationAlgorithm">The machineKey validationAlgorithm found in your web.config</param>
        /// <returns>An encoded string</returns>
        public static string ProtectCookie(OwinAuthenticationTicket ticket, string decryptionKey, string validationKey,
                                           string decryptionAlgorithm = "AES", string validationAlgorithm = "HMACSHA1")
        {
            var serializer     = new OwinTicketSerializer();
            var serializedData = serializer.Serialize(ticket);

            var protectedData = Protect(serializedData, decryptionKey, validationKey,
                                        decryptionAlgorithm, validationAlgorithm,
                                        "User.MachineKey.Protect",
                                        "Microsoft.Owin.Security.Cookies.CookieAuthenticationMiddleware", "ApplicationCookie", "v1");

            var encoded = WebEncoders.Base64UrlEncode(protectedData);

            return(encoded);
        }
Пример #4
0
        /// <summary>
        /// Serializes, encrypts and encodes an AuthenticationTicket
        /// created by OWIN's OAuth server implementation for the refresh token.
        /// </summary>
        /// <param name="ticket">The v3 AuthenticationTicket</param>
        /// <param name="decryptionKey">The machineKey decryptionKey found in your web.config</param>
        /// <param name="validationKey">The machineKey validationKey found in your web.config</param>
        /// <param name="decryptionAlgorithm">The machineKey decryptionAlgorithm found in your web.config (Auto == AES)</param>
        /// <param name="validationAlgorithm">The machineKey validationAlgorithm found in your web.config</param>
        /// <returns>An encoded string</returns>
        public static string ProtectOAuthRefreshToken(OwinAuthenticationTicket ticket, string decryptionKey, string validationKey,
                                                      string decryptionAlgorithm = "AES", string validationAlgorithm = "HMACSHA1")
        {
            var serializer     = new OwinTicketSerializer();
            var serializedData = serializer.Serialize(ticket);

            var protectedData = Protect(serializedData, decryptionKey, validationKey,
                                        decryptionAlgorithm, validationAlgorithm,
                                        "User.MachineKey.Protect",
                                        "Microsoft.Owin.Security.OAuth", "Refresh_Token", "v1");

            var encoded = WebEncoders.Base64UrlEncode(protectedData);

            return(encoded);
        }