Skip to content

Commit c7d58ee

Browse files
authored
Merge pull request #277 from Azure/dev
Merge to master for releasing 1.0.4
2 parents 9a61ec3 + 592bbe5 commit c7d58ee

File tree

25 files changed

+420
-68
lines changed

25 files changed

+420
-68
lines changed

AzureSignalR.sln

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.SignalR.Asp
4242
EndProject
4343
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.Azure.SignalR.AspNet.Tests", "test\Microsoft.Azure.SignalR.AspNet.Tests\Microsoft.Azure.SignalR.AspNet.Tests.csproj", "{4F12F3CF-3B6F-4E7F-9DF9-0E128978BD77}"
4444
EndProject
45+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AspNet.ChatSample", "AspNet.ChatSample", "{6E50C30D-3ECB-4C66-A579-2528C56924BB}"
46+
EndProject
47+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.ChatSample.SelfHostServer", "samples\AspNet.ChatSample\AspNet.ChatSample.SelfHostServer\AspNet.ChatSample.SelfHostServer.csproj", "{CA7F8B59-F1DA-400C-A114-467664C715ED}"
48+
EndProject
49+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AspNet.ChatSample.CSharpClient", "samples\AspNet.ChatSample\AspNet.ChatSample.CSharpClient\AspNet.ChatSample.CSharpClient.csproj", "{38522915-6EA5-4F1D-B6EC-7FE4B178F579}"
50+
EndProject
4551
Global
4652
GlobalSection(SolutionConfigurationPlatforms) = preSolution
4753
Debug|Any CPU = Debug|Any CPU
@@ -84,6 +90,14 @@ Global
8490
{4F12F3CF-3B6F-4E7F-9DF9-0E128978BD77}.Debug|Any CPU.Build.0 = Debug|Any CPU
8591
{4F12F3CF-3B6F-4E7F-9DF9-0E128978BD77}.Release|Any CPU.ActiveCfg = Release|Any CPU
8692
{4F12F3CF-3B6F-4E7F-9DF9-0E128978BD77}.Release|Any CPU.Build.0 = Release|Any CPU
93+
{CA7F8B59-F1DA-400C-A114-467664C715ED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
94+
{CA7F8B59-F1DA-400C-A114-467664C715ED}.Debug|Any CPU.Build.0 = Debug|Any CPU
95+
{CA7F8B59-F1DA-400C-A114-467664C715ED}.Release|Any CPU.ActiveCfg = Release|Any CPU
96+
{CA7F8B59-F1DA-400C-A114-467664C715ED}.Release|Any CPU.Build.0 = Release|Any CPU
97+
{38522915-6EA5-4F1D-B6EC-7FE4B178F579}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
98+
{38522915-6EA5-4F1D-B6EC-7FE4B178F579}.Debug|Any CPU.Build.0 = Debug|Any CPU
99+
{38522915-6EA5-4F1D-B6EC-7FE4B178F579}.Release|Any CPU.ActiveCfg = Release|Any CPU
100+
{38522915-6EA5-4F1D-B6EC-7FE4B178F579}.Release|Any CPU.Build.0 = Release|Any CPU
87101
EndGlobalSection
88102
GlobalSection(SolutionProperties) = preSolution
89103
HideSolutionNode = FALSE
@@ -98,6 +112,9 @@ Global
98112
{367FD2C0-A505-4761-B229-AA3948D25F21} = {2429FBD8-1FCE-4C42-AA28-DF32F7249E77}
99113
{235BF797-E3A2-4EEB-8D82-0C0BE1380663} = {DA69F624-5398-4884-87E4-B816698CDE65}
100114
{4F12F3CF-3B6F-4E7F-9DF9-0E128978BD77} = {2429FBD8-1FCE-4C42-AA28-DF32F7249E77}
115+
{6E50C30D-3ECB-4C66-A579-2528C56924BB} = {C4BC9889-B49F-41B6-806B-F84941B2549B}
116+
{CA7F8B59-F1DA-400C-A114-467664C715ED} = {6E50C30D-3ECB-4C66-A579-2528C56924BB}
117+
{38522915-6EA5-4F1D-B6EC-7FE4B178F579} = {6E50C30D-3ECB-4C66-A579-2528C56924BB}
101118
EndGlobalSection
102119
GlobalSection(ExtensibilityGlobals) = postSolution
103120
SolutionGuid = {7945A4E4-ACDB-4F6E-95CA-6AC6E7C2CD59}

build/dependencies.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
<MicrosoftExtensionsPrimitivesPackageVersion>2.1.0</MicrosoftExtensionsPrimitivesPackageVersion>
1818

1919
<!-- Azure ASP.NET SignalR -->
20-
<MicrosoftAspNetSignalRPackageVersion>2.4.0-preview2-20181018-02</MicrosoftAspNetSignalRPackageVersion>
20+
<MicrosoftAspNetSignalRPackageVersion>2.4.0</MicrosoftAspNetSignalRPackageVersion>
2121
<MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>2.1.0</MicrosoftAspNetCoreConnectionsAbstractionsPackageVersion>
2222
<MicrosoftExtensionsLoggingTraceSourcePackageVersion>2.1.0</MicrosoftExtensionsLoggingTraceSourcePackageVersion>
2323

@@ -27,6 +27,8 @@
2727
<!-- Samples -->
2828
<MicrosoftAspNetCorePackageVersion>2.1.0</MicrosoftAspNetCorePackageVersion>
2929
<NewtonsoftJsonPackageVersion>11.0.2</NewtonsoftJsonPackageVersion>
30+
<MicrosoftOwinPackageVersion>2.1.0</MicrosoftOwinPackageVersion>
31+
<OwinPackageVersion>1.0.0</OwinPackageVersion>
3032

3133
<!--Testing -->
3234
<MicrosoftAspNetCoreSignalRProtocolsMessagePackPackageVersion>1.0.0</MicrosoftAspNetCoreSignalRProtocolsMessagePackPackageVersion>

docs/use-signalr-service.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,13 @@ The access token is returned in the response to client's negotiate request.
157157
- When `ServerSentEvent` or `LongPolling` is used as transport, client connection will be closed due to authentication failure after the expire time.
158158
You can increase this value to avoid client disconnect.
159159

160+
#### `ClaimProvider`
161+
- Default value is `null`.
162+
- This option controls what claims you want to associate with the client connection.
163+
It will be used when Service SDK generates access token for client in client's negotiate request.
164+
By default, all claims from `IOwinContext.Authentication.User` of the negotiate request will be reserved.
165+
- Normally you should leave this option as is. Make sure you understand what will happen before customizing it.
166+
160167
#### `ConnectionString`
161168
- Default value is the `Azure:SignalR:ConnectionString` `connectionString` or `appSetting` in `web.config` file.
162169
- It can be reconfigured, but please make sure the value is **NOT** hard coded.
@@ -169,6 +176,7 @@ app.Map("/signalr",subApp => subApp.RunAzureSignalR(this.GetType().FullName, new
169176
{
170177
options.ConnectionCount = 1;
171178
options.AccessTokenLifetime = TimeSpan.FromDays(1);
179+
options.ClaimProvider = context => context.Authentication?.User.Claims;
172180
}));
173181
```
174182

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<PackageReference Include="Microsoft.AspNet.SignalR.Client" Version="$(MicrosoftAspNetSignalRPackageVersion)" />
10+
</ItemGroup>
11+
</Project>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using System.Threading.Tasks;
6+
using Microsoft.AspNet.SignalR.Client;
7+
8+
namespace AspNet.ChatSample.CSharpClient
9+
{
10+
class Program
11+
{
12+
static async Task Main(string[] args)
13+
{
14+
var url = "http://localhost:8009";
15+
var proxy = await ConnectAsync(url);
16+
var currentUser = Guid.NewGuid().ToString("N");
17+
18+
Mode mode = Mode.Broadcast;
19+
if (args.Length > 0)
20+
{
21+
Enum.TryParse(args[0], true, out mode);
22+
}
23+
24+
Console.WriteLine($"Logged in as user {currentUser}");
25+
var input = Console.ReadLine();
26+
while (!string.IsNullOrEmpty(input))
27+
{
28+
switch (mode)
29+
{
30+
case Mode.Broadcast:
31+
await proxy.Invoke("BroadcastMessage", currentUser, input);
32+
33+
break;
34+
case Mode.Echo:
35+
await proxy.Invoke("echo", input);
36+
break;
37+
default:
38+
break;
39+
}
40+
41+
input = Console.ReadLine();
42+
}
43+
}
44+
45+
private enum Mode
46+
{
47+
Broadcast,
48+
Echo,
49+
}
50+
51+
private static async Task<IHubProxy> ConnectAsync(string url)
52+
{
53+
var writer = Console.Out;
54+
var connection = new HubConnection(url)
55+
{
56+
TraceWriter = writer,
57+
TraceLevel = TraceLevels.StateChanges
58+
};
59+
60+
connection.Closed += () =>
61+
{
62+
Console.WriteLine($"{connection.ConnectionId} is closed");
63+
};
64+
65+
connection.Error += e =>
66+
{
67+
Console.WriteLine(e);
68+
};
69+
70+
var hubProxy = connection.CreateHubProxy("ChatHub");
71+
hubProxy.On<string, string>("BroadcastMessage", BroadcastMessage);
72+
hubProxy.On<string>("Echo", Echo);
73+
74+
await connection.Start();
75+
76+
return hubProxy;
77+
}
78+
79+
private static void BroadcastMessage(string name, string message)
80+
{
81+
Console.WriteLine($"{name}: {message}");
82+
}
83+
84+
private static void Echo(string message)
85+
{
86+
Console.WriteLine(message);
87+
}
88+
}
89+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>net461</TargetFramework>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<PackageReference Include="Microsoft.Owin" Version="$(MicrosoftOwinPackageVersion)" />
9+
<PackageReference Include="Microsoft.Owin.Cors" Version="$(MicrosoftOwinPackageVersion)" />
10+
<PackageReference Include="Microsoft.Owin.Diagnostics" Version="$(MicrosoftOwinPackageVersion)" />
11+
<PackageReference Include="Microsoft.Owin.Host.HttpListener" Version="$(MicrosoftOwinPackageVersion)" />
12+
<PackageReference Include="Microsoft.Owin.Hosting" Version="$(MicrosoftOwinPackageVersion)" />
13+
<PackageReference Include="Newtonsoft.Json" Version="$(NewtonsoftJsonPackageVersion)" />
14+
<PackageReference Include="Owin" Version="$(OwinPackageVersion)" />
15+
<PackageReference Include="Microsoft.AspNet.SignalR" Version="$(MicrosoftAspNetSignalRPackageVersion)" />
16+
<ProjectReference Include="..\..\..\src\Microsoft.Azure.SignalR.AspNet\Microsoft.Azure.SignalR.AspNet.csproj" />
17+
<ProjectReference Include="..\..\..\src\Microsoft.Azure.SignalR.Common\Microsoft.Azure.SignalR.Common.csproj" />
18+
<ProjectReference Include="..\..\..\src\Microsoft.Azure.SignalR.Protocols\Microsoft.Azure.SignalR.Protocols.csproj" />
19+
20+
<Reference Include="System" />
21+
<Reference Include="System.Core" />
22+
<Reference Include="Microsoft.CSharp" />
23+
</ItemGroup>
24+
25+
</Project>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Diagnostics;
5+
using Microsoft.AspNet.SignalR;
6+
7+
namespace AspNet.ChatSample.SelfHostServer
8+
{
9+
public class ChatHub : Hub
10+
{
11+
public void BroadcastMessage(string name, string message)
12+
{
13+
Clients.All.BroadcastMessage(name, message);
14+
Trace.TraceInformation("Broadcasting...");
15+
}
16+
17+
public void Echo(string message)
18+
{
19+
Clients.Client(Context.ConnectionId).Echo($"{message} (echo from server, Client IP: {GetIpAddress()})");
20+
Trace.TraceInformation("Echo...");
21+
}
22+
23+
private string GetIpAddress()
24+
{
25+
object address = null;
26+
Context.Request.Environment?.TryGetValue("server.RemoteIpAddress", out address);
27+
return address as string;
28+
}
29+
}
30+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System;
5+
using Microsoft.Owin.Hosting;
6+
7+
namespace AspNet.ChatSample.SelfHostServer
8+
{
9+
class Program
10+
{
11+
static void Main(string[] args)
12+
{
13+
using (WebApp.Start<Startup>("http://localhost:8009"))
14+
{
15+
Console.WriteLine("Server running at http://localhost:8009/");
16+
Console.ReadLine();
17+
}
18+
}
19+
}
20+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Diagnostics;
5+
using Microsoft.AspNet.SignalR;
6+
using Microsoft.Owin;
7+
using Owin;
8+
9+
[assembly: OwinStartup(typeof(AspNet.ChatSample.SelfHostServer.Startup))]
10+
11+
namespace AspNet.ChatSample.SelfHostServer
12+
{
13+
public class Startup
14+
{
15+
public void Configuration(IAppBuilder app)
16+
{
17+
// app.MapSignalR();
18+
app.MapAzureSignalR(GetType().FullName);
19+
GlobalHost.TraceManager.Switch.Level = SourceLevels.Information;
20+
}
21+
}
22+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5"/>
5+
</startup>
6+
<connectionStrings>
7+
<add name="Azure:SignalR:ConnectionString" connectionString=""/>
8+
</connectionStrings>
9+
</configuration>

0 commit comments

Comments
 (0)