public StubOwinMiddleware( int statusCode, AuthenticationResponseChallenge challenge = null, AuthenticationResponseRevoke revoke = null, AuthenticationResponseGrant grant = null) : base(null) { this.statusCode = statusCode; this.challenge = challenge; this.revoke = revoke; this.grant = grant; }
public void SignIn(AuthenticationProperties properties, params ClaimsIdentity[] identities) { AuthenticationResponseRevoke priorRevoke = AuthenticationResponseRevoke; if (priorRevoke != null) { // Scan the sign-outs's and remove any with a matching auth type. string[] filteredSignOuts = priorRevoke.AuthenticationTypes .Where(authType => !identities.Any(identity => identity.AuthenticationType.Equals(authType, StringComparison.Ordinal))) .ToArray(); if (filteredSignOuts.Length < priorRevoke.AuthenticationTypes.Length) { if (filteredSignOuts.Length == 0) { AuthenticationResponseRevoke = null; } else { AuthenticationResponseRevoke = new AuthenticationResponseRevoke(filteredSignOuts); } } } AuthenticationResponseGrant priorGrant = AuthenticationResponseGrant; if (priorGrant == null) { AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(identities), properties); } else { ClaimsIdentity[] mergedIdentities = priorGrant.Principal.Identities.Concat(identities).ToArray(); if (properties != null) { // Update prior properties foreach (var propertiesPair in properties.Dictionary) { priorGrant.Properties.Dictionary[propertiesPair.Key] = propertiesPair.Value; } } AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(mergedIdentities), priorGrant.Properties); } }
public void SignOut(AuthenticationProperties properties, string[] authenticationTypes) { AuthenticationResponseGrant priorGrant = AuthenticationResponseGrant; if (priorGrant != null) { // Scan the sign-in's and remove any with a matching auth type. ClaimsIdentity[] filteredIdentities = priorGrant.Principal.Identities .Where(identity => !authenticationTypes.Contains(identity.AuthenticationType, StringComparer.Ordinal)) .ToArray(); if (filteredIdentities.Length < priorGrant.Principal.Identities.Count()) { if (filteredIdentities.Length == 0) { AuthenticationResponseGrant = null; } else { AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(filteredIdentities), priorGrant.Properties); } } } AuthenticationResponseRevoke priorRevoke = AuthenticationResponseRevoke; if (priorRevoke == null) { AuthenticationResponseRevoke = new AuthenticationResponseRevoke(authenticationTypes, properties); } else { if (properties != null && !object.ReferenceEquals(properties.Dictionary, priorRevoke.Properties.Dictionary)) { // Update prior properties foreach (var propertiesPair in properties.Dictionary) { priorRevoke.Properties.Dictionary[propertiesPair.Key] = propertiesPair.Value; } } // Cumulative auth types string[] mergedAuthTypes = priorRevoke.AuthenticationTypes.Concat(authenticationTypes).ToArray(); AuthenticationResponseRevoke = new AuthenticationResponseRevoke(mergedAuthTypes, priorRevoke.Properties); } }
public void SignOut(string[] authenticationTypes) { AuthenticationResponseGrant priorGrant = AuthenticationResponseGrant; if (priorGrant != null) { // Scan the sign-in's and remove any with a matching auth type. ClaimsIdentity[] filteredIdentities = priorGrant.Principal.Identities .Where(identity => !authenticationTypes.Contains(identity.AuthenticationType, StringComparer.Ordinal)) .ToArray(); if (filteredIdentities.Length < priorGrant.Principal.Identities.Count()) { if (filteredIdentities.Length == 0) { AuthenticationResponseGrant = null; } else { AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(filteredIdentities), priorGrant.Properties); } } } AuthenticationResponseRevoke priorRevoke = AuthenticationResponseRevoke; if (priorRevoke == null) { AuthenticationResponseRevoke = new AuthenticationResponseRevoke(authenticationTypes); } else { // Cumulative auth types string[] mergedAuthTypes = priorRevoke.AuthenticationTypes.Concat(authenticationTypes).ToArray(); AuthenticationResponseRevoke = new AuthenticationResponseRevoke(mergedAuthTypes); } }
public void SignIn(AuthenticationProperties properties, params ClaimsIdentity[] identities) { AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(identities), properties); }
public void SignOut(string[] authenticationTypes) { AuthenticationResponseGrant priorGrant = AuthenticationResponseGrant; if (priorGrant != null) { // Scan the sign-in's and remove any with a matching auth type. ClaimsIdentity[] filteredIdentities = priorGrant.Principal.Identities .Where(identity => !authenticationTypes.Contains(identity.AuthenticationType, StringComparer.Ordinal)) .ToArray(); if (filteredIdentities.Length < priorGrant.Principal.Identities.Count()) { if (filteredIdentities.Length == 0) { AuthenticationResponseGrant = null; } else { AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(filteredIdentities), priorGrant.Properties); } } } AuthenticationResponseRevoke priorRevoke = AuthenticationResponseRevoke; if (priorRevoke == null) { AuthenticationResponseRevoke = new AuthenticationResponseRevoke(authenticationTypes); } else { // Cumulative auth types string[] mergedAuthTypes = priorRevoke.AuthenticationTypes.Concat(authenticationTypes).ToArray(); AuthenticationResponseRevoke = new AuthenticationResponseRevoke(mergedAuthTypes); } }
public void SignIn(AuthenticationProperties properties, params ClaimsIdentity[] identities) { AuthenticationResponseRevoke priorRevoke = AuthenticationResponseRevoke; if (priorRevoke != null) { // Scan the sign-outs's and remove any with a matching auth type. string[] filteredSignOuts = priorRevoke.AuthenticationTypes .Where(authType => !identities.Any(identity => identity.AuthenticationType.Equals(authType, StringComparison.Ordinal))) .ToArray(); if (filteredSignOuts.Length < priorRevoke.AuthenticationTypes.Length) { if (filteredSignOuts.Length == 0) { AuthenticationResponseRevoke = null; } else { AuthenticationResponseRevoke = new AuthenticationResponseRevoke(filteredSignOuts); } } } AuthenticationResponseGrant priorGrant = AuthenticationResponseGrant; if (priorGrant == null) { AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(identities), properties); } else { ClaimsIdentity[] mergedIdentities = priorGrant.Principal.Identities.Concat(identities).ToArray(); if (properties != null) { // Update prior properties foreach (var propertiesPair in properties.Dictionary) { priorGrant.Properties.Dictionary[propertiesPair.Key] = propertiesPair.Value; } } AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(mergedIdentities), priorGrant.Properties); } }
public async Task GivenNextMiddlewareGrantsAuth_ItDropsForceSslCookie() { // Arrange var context = Fakes.CreateOwinContext(); var next = Fakes.CreateOwinMiddleware(); var app = new AppBuilder(); var grant = new AuthenticationResponseGrant(new ClaimsIdentity(), new AuthenticationProperties()); next.Setup(n => n.Invoke(context)) .Returns<IOwinContext>(c => { c.Authentication.AuthenticationResponseGrant = grant; return Task.FromResult<object>(null); }); context.Request .SetUrl("http://nuget.local/foo/bar/baz?qux=qooz"); var middleware = new ForceSslWhenAuthenticatedMiddleware(next.Object, app, "ForceSSL", 443); // Act await middleware.Invoke(context); // Assert OwinAssert.SetsCookie(context.Response, "ForceSSL", "true"); }
public void Grant(ClaimsPrincipal principal, AuthenticationExtra extra) { AuthenticationResponseGrant = new AuthenticationResponseGrant(principal, extra); }
public void Grant(ClaimsPrincipal principal) { AuthenticationResponseGrant = new AuthenticationResponseGrant(principal, new AuthenticationExtra()); }
public void Grant(ClaimsIdentity identity, AuthenticationExtra extra) { AuthenticationResponseGrant = new AuthenticationResponseGrant(identity, extra); }
public void Grant(ClaimsIdentity identity) { AuthenticationResponseGrant = new AuthenticationResponseGrant(identity, new AuthenticationExtra()); }
public void Grant(ClaimsPrincipal principal, IDictionary<string, string> extra) { AuthenticationResponseGrant = new AuthenticationResponseGrant(principal, extra); }
public void Grant(ClaimsIdentity identity, IDictionary<string, string> extra) { AuthenticationResponseGrant = new AuthenticationResponseGrant(identity, extra); }
public void SignOut(AuthenticationProperties properties, string[] authenticationTypes) { AuthenticationResponseGrant priorGrant = AuthenticationResponseGrant; if (priorGrant != null) { // Scan the sign-in's and remove any with a matching auth type. ClaimsIdentity[] filteredIdentities = priorGrant.Principal.Identities .Where(identity => !authenticationTypes.Contains(identity.AuthenticationType, StringComparer.Ordinal)) .ToArray(); if (filteredIdentities.Length < priorGrant.Principal.Identities.Count()) { if (filteredIdentities.Length == 0) { AuthenticationResponseGrant = null; } else { AuthenticationResponseGrant = new AuthenticationResponseGrant(new ClaimsPrincipal(filteredIdentities), priorGrant.Properties); } } } AuthenticationResponseRevoke priorRevoke = AuthenticationResponseRevoke; if (priorRevoke == null) { AuthenticationResponseRevoke = new AuthenticationResponseRevoke(authenticationTypes, properties); } else { if (properties != null && !object.ReferenceEquals(properties.Dictionary, priorRevoke.Properties.Dictionary)) { // Update prior properties foreach (var propertiesPair in properties.Dictionary) { priorRevoke.Properties.Dictionary[propertiesPair.Key] = propertiesPair.Value; } } // Cumulative auth types string[] mergedAuthTypes = priorRevoke.AuthenticationTypes.Concat(authenticationTypes).ToArray(); AuthenticationResponseRevoke = new AuthenticationResponseRevoke(mergedAuthTypes, priorRevoke.Properties); } }