Net Maui signal hub authentication #22441
Unanswered
waldevelop
asked this question in
Q&A
Replies: 1 comment
-
I try to change the request in case it's not enough clear. How is it possible to send a message to a specific user from signal hub ? I suppose the only way is creating a match (in my case inside the DB) between the Userid identity and his connectionid. And to do this job I need to store in the db this match as soon as the user sends a message to the server. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have 2 applications, one Net Maui used in Android environment where I created a sort of chat between users and one Blazor web in. Net 8 running on the server side I use to show web pages with back end information from DB and to handle the Net Maui users authentication. In Net Maui application I authenticated the users receiving a token from the server application and then I saved it in the securestorage. I implemented the refreshtoken mechanism to avoid the user to login again. in the server side the users are authenticated using a cookie.
Everything is working fine.
The problem is when I need to know in the signal hub on the server side application, which user is sending messages because if I've well understood one of the options is to match and then save in the DB for instance the connectionid with the identity userid but inside this method Context.User is always empty
public class ChatHub : Hub
{
public override async Task OnConnectedAsync()
{
var user = Context.User
}
}
I tried to send the accesstoken from the client application using this
_connection = new HubConnectionBuilder()
.WithUrl(url,options =>
{
options.AccessTokenProvider = () => Task.FromResult(accesstoken);
})
.Build();
where accesstoken is the value I get from the securestorage but in the server side this value is empty using this piece of code supposing the accesstoken is automatically sent using a querystring
public class ChatHub : Hub
{
public override async Task OnConnectedAsync()
{
var t = Context.GetHttpContext();
var jwtToken = t.Request.Query["access_token"];
}
}
Is there any sample where I can find a solution ? I'm stucked since 3 days...
Thanks
Beta Was this translation helpful? Give feedback.
All reactions