Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for SignalR core python client (II): Authentication
Andrés Baamonde Lozano
Andrés Baamonde Lozano

Posted on • Edited on

     

SignalR core python client (II): Authentication

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());...
Enter fullscreen modeExit fullscreen mode

Create user on the web

Register

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"]
Enter fullscreen modeExit fullscreen mode

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()
Enter fullscreen modeExit fullscreen mode

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

Github
Pypi

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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Bohemian Developer
  • Location
    A coruña
  • Joined

More fromAndrés Baamonde Lozano

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp