
Intro
As i introduced on myprevious post, next step on my library was authentication on SignalR Core Hubs. A good guide and example of this authentication is this:aspnet docs. You can donwload fully working example on theirgithub.
Once introduction is finished, let's go to the playground:
Server side
Quick fix, memory database
Creating a database on disk for this example ... no thanks
Go to Startup.cs, comment UseSqlServer and add UseInMemoryDatabase
...publicvoidConfigureServices(IServiceCollectionservices){services.AddDbContext<ApplicationDbContext>(options=>// options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")options.UseInMemoryDatabase());...
Create user on the web
Client side
First, get auth token
Post request of this example is a form-data, response is a JSON.
defsignalr_core_example_login(url,user,username_password):response=requests.post(url,data={"email":user,"password":username_password})returnresponse.json()["token"]
Build connection and add signalr event handlers
token=signalr_core_example_login(login_url,username,password)hub_connection=HubConnection(server_url,token=token,negotiate_headers={"Authorization":"Bearer"+token})hub_connection.build()hub_connection.on("ReceiveSystemMessage",print)hub_connection.on("ReceiveChatMessage",print)hub_connection.on("ReceiveDirectMessage",print)hub_connection.start()
Now you have connection initialized and you can send messages auth through signalr hubs.
Fully example
Future
- message pack
- Auth (now only working by querystring negotiate)
Links
I'm trying to build this library with simplest way possible, so if you think that there is a better way to do it, leave a comment. Asap i'll edit github library contribute section, so any contribution is welcommed. There is a lot of work to do with these, messagepack. streams ..
Thank you for reading, and write any thought below :D
Top comments(0)
For further actions, you may consider blocking this person and/orreporting abuse