+i used this solution to implement Token Based Authentication using ASP.NET Web API 2, Owin, and Identity...which worked out excellently well. i used this other solution and thi
I followed this:
first Add the JWT to the query string:'
this.connection = $['hubConnection']();
this.connection.qs = { 'access_token': token}
then in thestartup.cs
,before JwtBearerAuthentication, add the token to the header:
app.Use(async (context, next) =>
{
if (string.IsNullOrWhiteSpace(context.Request.Headers["Authorization"]) && context.Request.QueryString.HasValue)
{
var token = context.Request.QueryString.Value.Split('&').SingleOrDefault(x => x.Contains("access_token"))?.Split('=')[1];
if (!string.IsNullOrWhiteSpace(token))
{
context.Request.Headers.Add("Authorization", new[] { $"Bearer {token}" });
}
}
await next.Invoke();
});
var keyResolver = new JwtSigningKeyResolver(new AuthenticationKeyContainer());
app.UseJwtBearerAuthentication(
new JwtBearerAuthenticationOptions
{
AuthenticationMode = AuthenticationMode.Active,
TokenValidationParameters = new TokenValidationParameters()
{
ValidAudience = ConfigurationUtil.ocdpAuthAudience,
ValidIssuer = ConfigurationUtil.ocdpAuthZero,
IssuerSigningKeyResolver = (token, securityToken, kid, validationParameters) => keyResolver.GetSigningKey(kid)
}
});
ValidateSignalRConnectionData(app);
var hubConfiguration = new HubConfiguration
{
EnableDetailedErrors = true
};
app.MapSignalR(hubConfiguration);