Handle Authentication and WebSocket API changes.

This commit is contained in:
Chris Ross 2015-04-23 16:06:18 -07:00
parent 1bb35041e9
commit b0d0e94aba
4 changed files with 17 additions and 17 deletions

View File

@ -21,10 +21,10 @@ namespace SelfHostServer
app.Run(async context =>
{
if (context.IsWebSocketRequest)
if (context.WebSockets.IsWebSocketRequest)
{
byte[] bytes = Encoding.ASCII.GetBytes("Hello World: " + DateTime.Now);
WebSocket webSocket = await context.AcceptWebSocketAsync();
WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync();
await webSocket.SendAsync(new ArraySegment<byte>(bytes, 0, bytes.Length), WebSocketMessageType.Text, true, CancellationToken.None);
await webSocket.CloseAsync(WebSocketCloseStatus.NormalClosure, "Goodbye", CancellationToken.None);
webSocket.Dispose();

View File

@ -44,7 +44,7 @@ namespace Microsoft.AspNet.Server.WebListener
_customChallenges = AuthenticationSchemes.None;
}
public void Authenticate(IAuthenticateContext context)
public void Authenticate(AuthenticateContext context)
{
var user = _requestContext.User;
var identity = user == null ? null : (ClaimsIdentity)user.Identity;
@ -67,13 +67,13 @@ namespace Microsoft.AspNet.Server.WebListener
}
}
public Task AuthenticateAsync(IAuthenticateContext context)
public Task AuthenticateAsync(AuthenticateContext context)
{
Authenticate(context);
return Task.FromResult(0);
}
public void Challenge(IChallengeContext context)
public void Challenge(ChallengeContext context)
{
foreach (var scheme in ListEnabledAuthSchemes())
{
@ -90,7 +90,7 @@ namespace Microsoft.AspNet.Server.WebListener
_requestContext.AuthenticationChallenges = _customChallenges;
}
public void GetDescriptions(IDescribeSchemesContext context)
public void GetDescriptions(DescribeSchemesContext context)
{
// TODO: Caching, this data doesn't change per request.
foreach (var scheme in ListEnabledAuthSchemes())
@ -99,12 +99,12 @@ namespace Microsoft.AspNet.Server.WebListener
}
}
public void SignIn(ISignInContext context)
public void SignIn(SignInContext context)
{
// Not supported
}
public void SignOut(ISignOutContext context)
public void SignOut(SignOutContext context)
{
// Not supported
}

View File

@ -410,7 +410,7 @@ namespace Microsoft.AspNet.Server.WebListener
}
}
Task<WebSocket> IHttpWebSocketFeature.AcceptAsync(IWebSocketAcceptContext context)
Task<WebSocket> IHttpWebSocketFeature.AcceptAsync(WebSocketAcceptContext context)
{
// TODO: Advanced params
string subProtocol = null;

View File

@ -201,7 +201,7 @@ namespace Microsoft.AspNet.Server.WebListener
using (Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address, env =>
{
var context = new DefaultHttpContext((IFeatureCollection)env);
var resultList = context.GetAuthenticationSchemes();
var resultList = context.Authentication.GetAuthenticationSchemes();
if (authType == AuthenticationSchemes.AllowAnonymous)
{
Assert.Equal(0, resultList.Count());
@ -236,7 +236,7 @@ namespace Microsoft.AspNet.Server.WebListener
using (Utilities.CreateHttpAuthServer(authType | AuthenticationSchemes.AllowAnonymous, out address, env =>
{
var context = new DefaultHttpContext((IFeatureCollection)env);
var resultList = context.GetAuthenticationSchemes();
var resultList = context.Authentication.GetAuthenticationSchemes();
Assert.Equal(4, resultList.Count());
return Task.FromResult(0);
}))
@ -265,7 +265,7 @@ namespace Microsoft.AspNet.Server.WebListener
Assert.False(context.User.Identity.IsAuthenticated);
foreach (var scheme in authTypeList)
{
var authResults = context.Authenticate(scheme);
var authResults = context.Authentication.Authenticate(scheme);
Assert.Null(authResults);
}
return Task.FromResult(0);
@ -296,7 +296,7 @@ namespace Microsoft.AspNet.Server.WebListener
var count = 0;
foreach (var scheme in authTypeList)
{
var authResults = context.Authenticate(scheme);
var authResults = context.Authentication.Authenticate(scheme);
if (authResults != null)
{
count++;
@ -327,7 +327,7 @@ namespace Microsoft.AspNet.Server.WebListener
var context = new DefaultHttpContext((IFeatureCollection)env);
Assert.NotNull(context.User);
Assert.False(context.User.Identity.IsAuthenticated);
context.Response.Challenge();
context.Authentication.Challenge();
return Task.FromResult(0);
}))
{
@ -355,7 +355,7 @@ namespace Microsoft.AspNet.Server.WebListener
Assert.False(context.User.Identity.IsAuthenticated);
foreach (var scheme in authTypeList)
{
context.Response.Challenge(scheme);
context.Authentication.Challenge(scheme);
}
return Task.FromResult(0);
}))
@ -381,7 +381,7 @@ namespace Microsoft.AspNet.Server.WebListener
var context = new DefaultHttpContext((IFeatureCollection)env);
Assert.NotNull(context.User);
Assert.False(context.User.Identity.IsAuthenticated);
context.Response.Challenge(authType.ToString());
context.Authentication.Challenge(authType.ToString());
return Task.FromResult(0);
}))
{
@ -409,7 +409,7 @@ namespace Microsoft.AspNet.Server.WebListener
var context = new DefaultHttpContext((IFeatureCollection)env);
Assert.NotNull(context.User);
Assert.False(context.User.Identity.IsAuthenticated);
Assert.Throws<InvalidOperationException>(() => context.Response.Challenge(authType.ToString()));
Assert.Throws<InvalidOperationException>(() => context.Authentication.Challenge(authType.ToString()));
return Task.FromResult(0);
}))
{