Modified a few for SetUser method

This commit is contained in:
sta 2014-11-20 11:44:30 +09:00
parent f4f50de125
commit 55527ef514
2 changed files with 9 additions and 8 deletions

View File

@ -115,8 +115,9 @@ namespace WebSocketSharp.Net
return true; return true;
var req = context.Request; var req = context.Request;
var authRes = req.Headers["Authorization"];
if (schm == AuthenticationSchemes.Basic) { if (schm == AuthenticationSchemes.Basic) {
var authRes = req.Headers["Authorization"];
if (authRes == null || !authRes.StartsWith ("basic", StringComparison.OrdinalIgnoreCase)) { if (authRes == null || !authRes.StartsWith ("basic", StringComparison.OrdinalIgnoreCase)) {
context.Response.CloseWithAuthChallenge ( context.Response.CloseWithAuthChallenge (
AuthenticationChallenge.CreateBasicChallenge (listener.Realm).ToBasicString ()); AuthenticationChallenge.CreateBasicChallenge (listener.Realm).ToBasicString ());
@ -125,7 +126,6 @@ namespace WebSocketSharp.Net
} }
} }
else if (schm == AuthenticationSchemes.Digest) { else if (schm == AuthenticationSchemes.Digest) {
var authRes = req.Headers["Authorization"];
if (authRes == null || !authRes.StartsWith ("digest", StringComparison.OrdinalIgnoreCase)) { if (authRes == null || !authRes.StartsWith ("digest", StringComparison.OrdinalIgnoreCase)) {
context.Response.CloseWithAuthChallenge ( context.Response.CloseWithAuthChallenge (
AuthenticationChallenge.CreateDigestChallenge (listener.Realm).ToDigestString ()); AuthenticationChallenge.CreateDigestChallenge (listener.Realm).ToDigestString ());
@ -139,7 +139,7 @@ namespace WebSocketSharp.Net
} }
var realm = listener.Realm; var realm = listener.Realm;
context.SetUser (schm, realm, listener.UserCredentialsFinder); context.SetUser (authRes, schm, realm, listener.UserCredentialsFinder);
if (req.IsAuthenticated) if (req.IsAuthenticated)
return true; return true;

View File

@ -44,8 +44,8 @@ using WebSocketSharp.Net.WebSockets;
namespace WebSocketSharp.Net namespace WebSocketSharp.Net
{ {
/// <summary> /// <summary>
/// Provides a set of methods and properties used to access the HTTP request and response /// Provides the access to the HTTP request and response information
/// information used by the <see cref="HttpListener"/>. /// used by the <see cref="HttpListener"/>.
/// </summary> /// </summary>
/// <remarks> /// <remarks>
/// The HttpListenerContext class cannot be inherited. /// The HttpListenerContext class cannot be inherited.
@ -160,15 +160,16 @@ namespace WebSocketSharp.Net
#region Internal Methods #region Internal Methods
internal void SetUser ( internal void SetUser (
string response,
AuthenticationSchemes scheme, AuthenticationSchemes scheme,
string realm, string realm,
Func<IIdentity, NetworkCredential> credentialsFinder) Func<IIdentity, NetworkCredential> credentialsFinder)
{ {
var authRes = AuthenticationResponse.Parse (_request.Headers ["Authorization"]); var res = AuthenticationResponse.Parse (response);
if (authRes == null) if (res == null)
return; return;
var id = authRes.ToIdentity (); var id = res.ToIdentity ();
if (id == null) if (id == null)
return; return;