Ejemplo n.º 1
0
        public static string DecryptAndAuthenticateContentUser(string token, string data)
        {         // should be called on content app
            string url = HttpContext.Current.Cache[GetCacheKey(token)] as string;

            if (string.IsNullOrEmpty(url))
            {
                return(null);
            }

            RPIdentity rpIdentity;

            try
            {
                string userData = EncryptionManager.Decrypt(data);
                rpIdentity = new RPIdentity(userData);
            }
            catch
            {
                return(null);
            }
            DateTime now = DateTime.Now;
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                2,
                rpIdentity.Name,
                now,
                now.Add(AuthenticationContentTimeout),
                false,
                rpIdentity.GetCookieString(),
                FormsAuthentication.FormsCookiePath
                );

            SetTicketToCookie(ticket);
            return(url);
        }
Ejemplo n.º 2
0
        public static string GenerateContentAuthenticationResponse(string token)
        {         // should be called on web app
            RPIdentity rpIdentity = (RPIdentity)HttpContext.Current.User.Identity;

            string data       = EncryptionManager.Encrypt(rpIdentity.GetCookieString());
            var    uriBuilder = new UriBuilder
            {
                Host   = WebUrlManager.Host,
                Scheme = HttpContext.Current.Request.Url.Scheme,
                Path   = "user/authenticate",
                Query  = $"token={token}&data={data}"
            };

            return(uriBuilder.ToString());
        }
Ejemplo n.º 3
0
        public static void AuthenticateRequest()
        {
            var cookie = HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie != null)
            {
                FormsAuthenticationTicket authTicket = FormsAuthentication.Decrypt(cookie.Value);
                try
                {
                    IIdentity userIdentity = new RPIdentity(authTicket);
                    HttpContext.Current.User = new GenericPrincipal(userIdentity, null);
                }
                catch
                {
                    FormsAuthentication.SignOut();
                }
            }
        }
Ejemplo n.º 4
0
        public static void SetAuthCookie(string userName, int userId, int organizationId, bool isPersistent)
        {
            if (userName == null)
            {
                userName = string.Empty;
            }

            var totalMinutes = isPersistent ? AuthenticationLongTimeout : AuthenticationShortTimeout;

            var rpIdentity = RPIdentity.Create(userName, userId, organizationId);

            DateTime now = DateTime.Now;
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                2,
                rpIdentity.Name,
                now,
                now.Add(totalMinutes),
                isPersistent,
                rpIdentity.GetCookieString(),
                FormsAuthentication.FormsCookiePath
                );

            SetTicketToCookie(ticket);
        }
Ejemplo n.º 5
0
        public static int?GetUserId()
        {
            RPIdentity rpIdentity = HttpContext.Current.User.Identity as RPIdentity;

            return(rpIdentity?.UserId);
        }
Ejemplo n.º 6
0
        public static string GetUserEmail()
        {
            RPIdentity rpIdentity = HttpContext.Current.User.Identity as RPIdentity;

            return(rpIdentity?.Name);
        }