Hi I am trying to get the following value
var userId = Context.User.FindFirst(ClaimTypes.MobilePhone)?.Value;
inside of the OnConnectedAsync() methid inside my Hub.
so I added the configuration in my ASP.Net core 8 backend Like this :
builder.Services.AddAuthentication(options =>
{
options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
}).AddJwtBearer(options =>
{
options.Events = new JwtBearerEvents
{
OnMessageReceived = context =>
{
var accessToken = context.Request.Query["access_token"];
var path = context.HttpContext.Request.Path;
if (!string.IsNullOrEmpty(accessToken) &&
(path.StartsWithSegments("/MyHub")))
{
context.Token = accessToken;
}
return Task.CompletedTask;
}
};
});
and inside my android application I added :
String access_token = tokenManager.getAccessToken();
HubConnection hubConnection = HubConnectionBuilder.create("someUrl/MyHub")
.withAccessTokenProvider(Single.defer(() -> {
return Single.just(access_token);
})).build();
The OnConnectedAsync() method is called normally but The is OnMessageReceived is never called when the client connects to the hub. after that when I add the [Authorize] attribut on my hub class. the client can no longer connect to the hub even if I am including the access_token in the request(see code above).
Thank you
What am I doing wrong here ?
Haythem Ben Slimene is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.