This commit is contained in:
Paul Schneider 2019-05-07 14:01:23 +01:00
commit 02160f1eaf
26 changed files with 129 additions and 132 deletions

View file

@ -91,10 +91,11 @@ namespace Yavsc {
SiteSettings settingsOptions, ILogger logger) {
app.UseIdentity ();
app.UseWhen (context => context.Request.Path.StartsWithSegments ("/api")
|| context.Request.Path.StartsWithSegments ("/live"),
branch => {
branch.UseJwtBearerAuthentication (
app.UseWhen ( context => context.Request.Path.StartsWithSegments ("/api")
|| context.Request.Path.StartsWithSegments ("/live") ,
branchLiveOrApi =>
{
branchLiveOrApi.UseJwtBearerAuthentication (
options => {
options.AuthenticationScheme = JwtBearerDefaults.AuthenticationScheme;
options.AutomaticAuthenticate = true;
@ -103,21 +104,21 @@ namespace Yavsc {
ProtectionProvider
));
options.Events = new JwtBearerEvents
{
OnReceivingToken = async context =>
{
var signalRTokenHeader = context.Request.Query["signalRTokenHeader"];
if (!string.IsNullOrEmpty(signalRTokenHeader) &&
(context.HttpContext.WebSockets.IsWebSocketRequest || context.Request.Headers["Accept"] == "text/event-stream"))
{
context.Token = context.Request.Query["signalRTokenHeader"];
}
}
};
}
);
OnReceivingToken = context =>
{
return Task.Run( () => {
var signalRTokenHeader = context.Request.Query["signalRTokenHeader"];
if (!string.IsNullOrEmpty(signalRTokenHeader) &&
(context.HttpContext.WebSockets.IsWebSocketRequest || context.Request.Headers["Accept"] == "text/event-stream"))
{
context.Token = context.Request.Query["signalRTokenHeader"];
}
});
}
};
});
});
app.UseWhen (context => !context.Request.Path.StartsWithSegments ("/api") && !context.Request.Path.StartsWithSegments ("/live"),
branch => {