コード例 #1
0
ファイル: AuthenticateResult.cs プロジェクト: tkggand/katana
 /// <summary>
 /// Create an instance of the result object
 /// </summary>
 /// <param name="identity">Assigned to the Identity property. May be null.</param>
 /// <param name="extra">Assigned to the Extra property. An empty Extra instance is created if needed.</param>
 /// <param name="description">Assigned to the Description property. An empty AuthenticationDescription instance is created if needed.</param>
 public AuthenticateResult(IIdentity identity, IDictionary<string, string> extra, IDictionary<string, object> description)
 {
     if (identity != null)
     {
         Identity = identity as ClaimsIdentity ?? new ClaimsIdentity(identity);
     }
     Extra = new AuthenticationExtra(extra);
     Description = new AuthenticationDescription(description);
 }
コード例 #2
0
 /// <summary>
 /// Create an instance of the result object
 /// </summary>
 /// <param name="identity">Assigned to the Identity property. May be null.</param>
 /// <param name="extra">Assigned to the Extra property. An empty Extra instance is created if needed.</param>
 /// <param name="description">Assigned to the Description property. An empty AuthenticationDescription instance is created if needed.</param>
 public AuthenticateResult(IIdentity identity, IDictionary <string, string> extra, IDictionary <string, object> description)
 {
     if (identity != null)
     {
         Identity = identity as ClaimsIdentity ?? new ClaimsIdentity(identity);
     }
     Extra       = new AuthenticationExtra(extra);
     Description = new AuthenticationDescription(description);
 }
コード例 #3
0
        public Task Invoke(IDictionary<string, object> env)
        {
            var request = new OwinRequest(env);
            var response = new OwinResponse(env);

            // The forms auth module has a bug where it null refs on a null Extra
            var headers = request.Get<IDictionary<string, string[]>>(Owin.Types.OwinConstants.RequestHeaders);

            var cookies = request.GetCookies();
            string cookieValue;
            if (cookies != null && cookies.TryGetValue("jabbr.id", out cookieValue))
            {
                AuthenticationTicket ticket = _ticketHandler.Unprotect(cookieValue);
                if (ticket != null && ticket.Extra == null)
                {
                    var extra = new AuthenticationExtra();
                    extra.IsPersistent = true;
                    extra.IssuedUtc = DateTime.UtcNow;
                    extra.ExpiresUtc = DateTime.UtcNow.AddDays(30);

                    var newTicket = new AuthenticationTicket(ticket.Identity, extra);

                    var cookieBuilder = new StringBuilder();
                    foreach (var cookie in cookies)
                    {
                        string value = cookie.Value;

                        if (cookie.Key == "jabbr.id")
                        {
                            // Create a new ticket preserving the identity of the user
                            // so they don't get logged out
                            value = _ticketHandler.Protect(newTicket);
                            response.AddCookie("jabbr.id", value, new CookieOptions
                            {
                                Expires = extra.ExpiresUtc.Value.UtcDateTime,
                                HttpOnly = true
                            });
                        }

                        if (cookieBuilder.Length > 0)
                        {
                            cookieBuilder.Append(";");
                        }

                        cookieBuilder.Append(cookie.Key)
                                     .Append("=")
                                     .Append(Uri.EscapeDataString(value));
                    }

                    headers["Cookie"] = new[] { cookieBuilder.ToString() };
                }
            }

            return _next(env);
        }
コード例 #4
0
        public AuthenticationResponseGrant(ClaimsPrincipal principal, AuthenticationExtra extra)
        {
            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }

            Principal = principal;
            Identity = principal.Identities.FirstOrDefault();
            Extra = extra;
        }
コード例 #5
0
        public AuthenticationResponseGrant(ClaimsPrincipal principal, AuthenticationExtra extra)
        {
            if (principal == null)
            {
                throw new ArgumentNullException("principal");
            }

            Principal = principal;
            Identity  = principal.Identities.FirstOrDefault();
            Extra     = extra;
        }
コード例 #6
0
ファイル: FixCookieHandler.cs プロジェクト: adamralph/JabbR
        public Task Invoke(IDictionary<string, object> env)
        {
            var request = new OwinRequest(env);
            var response = new OwinResponse(env);

            string cookieValue = request.Cookies["jabbr.id"];
            if (!String.IsNullOrEmpty(cookieValue))
            {
                AuthenticationTicket ticket = _ticketHandler.Unprotect(cookieValue);
                if (ticket != null && ticket.Extra == null)
                {
                    var extra = new AuthenticationExtra();
                    extra.IsPersistent = true;
                    extra.IssuedUtc = DateTime.UtcNow;
                    extra.ExpiresUtc = DateTime.UtcNow.AddDays(30);

                    var newTicket = new AuthenticationTicket(ticket.Identity, extra);

                    var cookieBuilder = new StringBuilder();
                    foreach (var cookie in request.Cookies)
                    {
                        string value = cookie.Value;

                        if (cookie.Key == "jabbr.id")
                        {
                            // Create a new ticket preserving the identity of the user
                            // so they don't get logged out
                            value = _ticketHandler.Protect(newTicket);
                            response.Cookies.Append("jabbr.id", value, new CookieOptions
                            {
                                Expires = extra.ExpiresUtc.Value.UtcDateTime,
                                HttpOnly = true
                            });
                        }

                        if (cookieBuilder.Length > 0)
                        {
                            cookieBuilder.Append(";");
                        }

                        cookieBuilder.Append(cookie.Key)
                                     .Append("=")
                                     .Append(Uri.EscapeDataString(value));
                    }

                    request.Headers["Cookie"] = cookieBuilder.ToString();
                }
            }

            return _next(env);
        }
コード例 #7
0
 public void SignIn(AuthenticationExtra extra, params ClaimsIdentity[] identities)
 {
     _response.Grant(new ClaimsPrincipal(identities), extra);
 }
コード例 #8
0
 public AuthenticationResponseChallenge(string[] authenticationTypes, AuthenticationExtra extra)
 {
     AuthenticationTypes = authenticationTypes;
     Extra = extra;
 }
コード例 #9
0
 /// <summary></summary>
 /// <param name="context"></param>
 /// <param name="authenticationType"> </param>
 /// <param name="claims"></param>
 /// <param name="nameClaimType"></param>
 /// <param name="roleClaimType"></param>
 /// <param name="isPersistent"></param>
 /// <exception cref="ArgumentNullException"></exception>
 public static void SignIn(this HttpContext context, string authenticationType, IEnumerable<Claim> claims, string nameClaimType, string roleClaimType, bool isPersistent)
 {
     if (authenticationType == null)
     {
         throw new ArgumentNullException("authenticationType");
     }
     if (claims == null)
     {
         throw new ArgumentNullException("claims");
     }
     if (nameClaimType == null)
     {
         throw new ArgumentNullException("nameClaimType");
     }
     if (roleClaimType == null)
     {
         throw new ArgumentNullException("roleClaimType");
     }
     var extra = new AuthenticationExtra { IsPersistent = isPersistent };
     context.SignIn(new ClaimsPrincipal(new ClaimsIdentity(claims, authenticationType, nameClaimType, roleClaimType)), extra);
 }
コード例 #10
0
        /// <summary></summary>
        /// <param name="context"></param>
        /// <param name="authenticationTypes"></param>
        public static void Challenge(this HttpContextBase context, string authenticationType, AuthenticationExtra extra)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            OwinResponse response = GetOwinResponse(context);
            response.Challenge(new[] { authenticationType }, extra);
        }
コード例 #11
0
        /// <summary></summary>
        /// <param name="context"></param>
        /// <param name="authenticationTypes"></param>
        /// <param name="extra"></param>
        public static void Challenge(this HttpContext context, string[] authenticationTypes, AuthenticationExtra extra)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }
            if (extra == null)
            {
                throw new ArgumentNullException("extra");
            }

            OwinResponse response = GetOwinResponse(context);
            response.Challenge(authenticationTypes, extra);
        }
コード例 #12
0
 public static void SignIn(this IAuthenticationManager authenticationManager, ClaimsIdentity identity)
 {
     var extra = new AuthenticationExtra();
     authenticationManager.SignIn(extra, identity);
 }
コード例 #13
0
        private static AuthenticationResponseChallenge AddChallengeAuthenticationType(
            AuthenticationResponseChallenge challenge, string authenticationType)
        {
            Contract.Assert(authenticationType != null);

            List<string> authenticationTypes = new List<string>();
            AuthenticationExtra extra;

            if (challenge != null)
            {
                string[] currentAuthenticationTypes = challenge.AuthenticationTypes;

                if (currentAuthenticationTypes != null)
                {
                    authenticationTypes.AddRange(currentAuthenticationTypes);
                }

                extra = challenge.Extra;
            }
            else
            {
                extra = new AuthenticationExtra();
            }

            authenticationTypes.Add(authenticationType);

            return new AuthenticationResponseChallenge(authenticationTypes.ToArray(), extra);
        }
コード例 #14
0
 public void Challenge(AuthenticationExtra extra, params string[] authenticationTypes)
 {
     _response.Challenge(authenticationTypes, extra);
 }
コード例 #15
0
 public AuthenticationTicket(ClaimsIdentity identity, AuthenticationExtra extra)
 {
     Identity = identity;
     Extra = extra;
 }
コード例 #16
0
ファイル: OwinResponse.net45.cs プロジェクト: tkggand/katana
 public void Challenge(string[] authenticationTypes, AuthenticationExtra extra)
 {
     StatusCode = 401;
     AuthenticationResponseChallenge = new AuthenticationResponseChallenge(authenticationTypes, extra);
 }
コード例 #17
0
ファイル: OwinResponse.net45.cs プロジェクト: tkggand/katana
 public void Grant(ClaimsPrincipal principal, AuthenticationExtra extra)
 {
     AuthenticationResponseGrant = new AuthenticationResponseGrant(principal, extra);
 }
コード例 #18
0
ファイル: OwinResponse.net45.cs プロジェクト: tkggand/katana
 public void Grant(ClaimsIdentity identity, AuthenticationExtra extra)
 {
     AuthenticationResponseGrant = new AuthenticationResponseGrant(identity, extra);
 }
コード例 #19
0
 public AuthenticationTicket(ClaimsIdentity identity, IDictionary <string, string> extra)
 {
     Identity = identity;
     Extra    = new AuthenticationExtra(extra);
 }
コード例 #20
0
 public AuthenticationTicket(ClaimsIdentity identity, AuthenticationExtra extra)
 {
     Identity = identity;
     Extra    = extra;
 }
コード例 #21
0
 public AuthenticationTicket(ClaimsIdentity identity, IDictionary<string, string> extra)
 {
     Identity = identity;
     Extra = new AuthenticationExtra(extra);
 }
コード例 #22
0
 public void Challenge(AuthenticationExtra extra, params string[] authenticationTypes)
 {
     _response.Challenge(authenticationTypes, extra);
 }
        public void SendAsync_LeavesAuthenticationChallenges_WhenExistingAuthenticationTypesIsNonEmpty()
        {
            // Arrange
            IHostPrincipalService principalService = CreateStubPrincipalService();
            HttpMessageHandler inner = CreateStubHandler();
            HttpMessageHandler handler = CreateProductUnderTest(principalService, inner);
            IDictionary<string, object> environment = CreateOwinEnvironment();
            OwinResponse owinResponse = new OwinResponse(environment);
            AuthenticationExtra extraWrapper = new AuthenticationExtra();
            string[] expectedAuthenticationTypes = new string[] { "Existing" };
            IDictionary<string, string> expectedExtra = extraWrapper.Properties;
            owinResponse.AuthenticationResponseChallenge = new AuthenticationResponseChallenge(
                expectedAuthenticationTypes, extraWrapper);

            using (HttpRequestMessage request = CreateRequestWithOwinEnvironment(environment))
            {
                // Act
                handler.SendAsync(request, CancellationToken.None);
            }

            // Assert
            AuthenticationResponseChallenge challenge = owinResponse.AuthenticationResponseChallenge;
            Assert.NotNull(challenge);
            Assert.Same(expectedAuthenticationTypes, challenge.AuthenticationTypes);
            AuthenticationExtra actualExtraWrapper = challenge.Extra;
            Assert.NotNull(actualExtraWrapper);
            Assert.Same(expectedExtra, actualExtraWrapper.Properties);
        }
コード例 #24
0
 public void SignIn(AuthenticationExtra extra, params ClaimsIdentity[] identities)
 {
     _response.Grant(new ClaimsPrincipal(identities), extra);
 }
コード例 #25
0
 public AuthenticationResponseChallenge(string[] authenticationTypes, AuthenticationExtra extra)
 {
     AuthenticationTypes = authenticationTypes;
     Extra = extra;
 }
コード例 #26
0
 public AuthenticationResponseGrant(ClaimsIdentity identity, AuthenticationExtra extra)
 {
     Principal = new ClaimsPrincipal(identity);
     Identity = identity;
     Extra = extra;
 }
コード例 #27
0
        /// <summary></summary>
        /// <param name="context"></param>
        /// <param name="user"></param>
        /// <param name="extra"></param>
        public static void SignIn(this HttpContext context, ClaimsPrincipal user, AuthenticationExtra extra)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            OwinResponse response = GetOwinResponse(context);
            response.Grant(user, extra);
        }
コード例 #28
0
 public AuthenticationResponseGrant(ClaimsIdentity identity, AuthenticationExtra extra)
 {
     Principal = new ClaimsPrincipal(identity);
     Identity  = identity;
     Extra     = extra;
 }