SignOutContext needs AuthenticationProperties

This commit is contained in:
Praburaj 2015-03-06 17:20:47 -08:00
parent 9463b08d7b
commit 58c45cd379
5 changed files with 23 additions and 9 deletions

View File

@ -11,13 +11,16 @@ namespace Microsoft.AspNet.Http.Core.Authentication
{ {
private bool _accepted; private bool _accepted;
public SignOutContext(string authenticationScheme) public SignOutContext([NotNull] string authenticationScheme, IDictionary<string, string> properties)
{ {
AuthenticationScheme = authenticationScheme; AuthenticationScheme = authenticationScheme;
Properties = properties ?? new Dictionary<string, string>(StringComparer.Ordinal);
} }
public string AuthenticationScheme { get; } public string AuthenticationScheme { get; }
public IDictionary<string, string> Properties { get; }
public bool Accepted public bool Accepted
{ {
get { return _accepted; } get { return _accepted; }

View File

@ -7,13 +7,11 @@ using System.IO;
using System.Linq; using System.Linq;
using System.Security.Claims; using System.Security.Claims;
using Microsoft.AspNet.FeatureModel; using Microsoft.AspNet.FeatureModel;
using Microsoft.AspNet.Http.Authentication;
using Microsoft.AspNet.Http.Core.Authentication;
using Microsoft.AspNet.Http.Core.Collections; using Microsoft.AspNet.Http.Core.Collections;
using Microsoft.AspNet.Http.Core.Infrastructure; using Microsoft.AspNet.Http.Core.Infrastructure;
using Microsoft.AspNet.Http.Core.Authentication;
using Microsoft.AspNet.Http.Infrastructure; using Microsoft.AspNet.Http.Infrastructure;
using Microsoft.AspNet.Http;
using Microsoft.AspNet.Http.Authentication;
using Microsoft.AspNet.Http.Authentication;
namespace Microsoft.AspNet.Http.Core namespace Microsoft.AspNet.Http.Core
{ {
@ -162,11 +160,11 @@ namespace Microsoft.AspNet.Http.Core
} }
} }
public override void SignOut(string authenticationScheme) public override void SignOut(string authenticationScheme, AuthenticationProperties properties)
{ {
var handler = HttpAuthenticationFeature.Handler; var handler = HttpAuthenticationFeature.Handler;
var signOutContext = new SignOutContext(authenticationScheme); var signOutContext = new SignOutContext(authenticationScheme, properties?.Dictionary);
if (handler != null) if (handler != null)
{ {
handler.SignOut(signOutContext); handler.SignOut(signOutContext);
@ -178,5 +176,10 @@ namespace Microsoft.AspNet.Http.Core
throw new InvalidOperationException("The following authentication scheme was not accepted: " + authenticationScheme); throw new InvalidOperationException("The following authentication scheme was not accepted: " + authenticationScheme);
} }
} }
public override void SignOut(string authenticationScheme)
{
SignOut(authenticationScheme, properties: null);
}
} }
} }

View File

@ -1,12 +1,16 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
namespace Microsoft.AspNet.Http.Authentication namespace Microsoft.AspNet.Http.Authentication
{ {
public interface ISignOutContext public interface ISignOutContext
{ {
string AuthenticationScheme { get; } string AuthenticationScheme { get; }
IDictionary<string, string> Properties { get; }
void Accept(); void Accept();
} }
} }

View File

@ -61,7 +61,7 @@ namespace Microsoft.AspNet.Http
public virtual void Challenge(IEnumerable<string> authenticationSchemes) public virtual void Challenge(IEnumerable<string> authenticationSchemes)
{ {
Challenge(properties: null, authenticationSchemes: authenticationSchemes); Challenge(properties: null, authenticationSchemes: authenticationSchemes);
} }
public virtual void Challenge(AuthenticationProperties properties, params string[] authenticationSchemes) public virtual void Challenge(AuthenticationProperties properties, params string[] authenticationSchemes)
@ -75,9 +75,11 @@ namespace Microsoft.AspNet.Http
public virtual void SignOut() public virtual void SignOut()
{ {
SignOut(authenticationScheme: null); SignOut(authenticationScheme: null, properties: null);
} }
public abstract void SignOut(string authenticationScheme); public abstract void SignOut(string authenticationScheme);
public abstract void SignOut(string authenticationScheme, AuthenticationProperties properties);
} }
} }

View File

@ -90,6 +90,8 @@ namespace Microsoft.AspNet.Http.Core.Tests
Assert.False(handler.SignedIn); Assert.False(handler.SignedIn);
context.Response.SignIn("ignored", user); context.Response.SignIn("ignored", user);
Assert.True(handler.SignedIn); Assert.True(handler.SignedIn);
context.Response.SignOut("ignored", new AuthenticationProperties() { RedirectUri = "~/logout" });
Assert.False(handler.SignedIn);
} }
private class AuthHandler : IAuthenticationHandler private class AuthHandler : IAuthenticationHandler