Skip to content

Commit 47e8efe

Browse files
committed
SignalR için jwt token ayarları yapıldı.
1 parent 199c0e5 commit 47e8efe

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

ChatSample/ChatSample/Startup.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text;
2+
using System.Threading.Tasks;
23
using ChatSample.Helpers;
34
using ChatSample.Hubs;
45
using ChatSample.IServices;
@@ -39,6 +40,20 @@ public void ConfigureServices (IServiceCollection services) {
3940
ValidateIssuer = false,
4041
ValidateAudience = false
4142
};
43+
x.Events = new JwtBearerEvents {
44+
OnMessageReceived = context => {
45+
var accessToken = context.Request.Query["access_token"];
46+
47+
// If the request is for our hub...
48+
var path = context.HttpContext.Request.Path;
49+
if (!string.IsNullOrEmpty (accessToken) &&
50+
(path.StartsWithSegments ("/hubs/chat"))) {
51+
// Read the token out of the query string
52+
context.Token = accessToken;
53+
}
54+
return Task.CompletedTask;
55+
}
56+
};
4257
});
4358

4459
// configure DI for application services

0 commit comments

Comments
 (0)