This repository has been archived by the owner on Dec 18, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 446
fix issue with incorrect user detection when Invoking for User #747
Merged
Merged
Changes from 11 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
07c4e79
fix issue with incorrect user detection when Invoking for User
ivankarpey 3408e09
fix failed testcases
ivankarpey 4572645
use proper extension method to avoid potential null reference exception
ivankarpey f534b4e
fix for channel name in redis version + follow SignalR team recommend…
ivankarpey 0da1a24
merge with latest changes from dev branch
ivankarpey fe6c28a
remove unncessary freespace
ivankarpey 3270d9e
remove whitespaces
ivankarpey 9445232
merge with latest changes from dev branch
ivankarpey b93e024
introduce IUserIdProvider to resolve user id
ivankarpey aee0337
Move IUserIdProvider from HubLifetimeManager to HubConnectionContext
ivankarpey 1548fe8
setting user id to connection context in hubendpoint
ivankarpey 8913166
String -> string
ivankarpey cbeb3c1
remove whitespaces
ivankarpey 012766f
remove whitespace
ivankarpey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ public class DefaultHubLifetimeManager<THub> : HubLifetimeManager<THub> | |
{ | ||
private long _nextInvocationId = 0; | ||
private readonly HubConnectionList _connections = new HubConnectionList(); | ||
|
||
public override Task AddGroupAsync(string connectionId, string groupName) | ||
{ | ||
if (connectionId == null) | ||
|
@@ -138,17 +138,14 @@ public override Task InvokeGroupAsync(string groupName, string methodName, objec | |
|
||
public override Task InvokeUserAsync(string userId, string methodName, object[] args) | ||
{ | ||
return InvokeAllWhere(methodName, args, connection => | ||
{ | ||
return string.Equals(connection.User.Identity.Name, userId, StringComparison.Ordinal); | ||
}); | ||
return InvokeAllWhere(methodName, args, connection => | ||
string.Equals(connection.UserIdentifier, userId, StringComparison.Ordinal)); | ||
} | ||
|
||
public override Task OnConnectedAsync(HubConnectionContext connection) | ||
{ | ||
// Set the hub groups feature | ||
connection.Features.Set<IHubGroupsFeature>(new HubGroupsFeature()); | ||
|
||
_connections.Add(connection); | ||
return Task.CompletedTask; | ||
} | ||
|
@@ -166,7 +163,7 @@ private async Task WriteAsync(HubConnectionContext connection, HubMessage hubMes | |
if (connection.Output.TryWrite(hubMessage)) | ||
{ | ||
break; | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove space |
||
} | ||
} | ||
|
||
|
@@ -194,4 +191,4 @@ private class HubGroupsFeature : IHubGroupsFeature | |
public HashSet<string> Groups { get; } = new HashSet<string>(StringComparer.OrdinalIgnoreCase); | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/Microsoft.AspNetCore.SignalR.Core/DefaultUserIdProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System.Security.Claims; | ||
|
||
namespace Microsoft.AspNetCore.SignalR.Core | ||
{ | ||
public class DefaultUserIdProvider : IUserIdProvider | ||
{ | ||
public string GetUserId(HubConnectionContext connection) | ||
{ | ||
return connection.User.FindFirst(ClaimTypes.NameIdentifier)?.Value; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
namespace Microsoft.AspNetCore.SignalR.Core | ||
{ | ||
public interface IUserIdProvider | ||
{ | ||
string GetUserId(HubConnectionContext connection); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -245,9 +245,9 @@ public override Task OnConnectedAsync(HubConnectionContext connection) | |
previousConnectionTask = WriteAsync(connection, message); | ||
}); | ||
|
||
if (connection.User.Identity.IsAuthenticated) | ||
if (!String.IsNullOrEmpty(connection.UserIdentifier)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: lowercase s in string |
||
{ | ||
var userChannel = _channelNamePrefix + ".user." + connection.User.Identity.Name; | ||
var userChannel = _channelNamePrefix + ".user." + connection.UserIdentifier; | ||
redisSubscriptions.Add(userChannel); | ||
|
||
var previousUserTask = Task.CompletedTask; | ||
|
1 change: 1 addition & 0 deletions
1
test/Microsoft.AspNetCore.SignalR.Tests/DefaultHubLifetimeManagerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove empty space