Authentication endpoint support for backend not built with node.js #630
Replies: 4 comments
-
Any plan to provide an authentication endpoint for a Flask backend? |
Beta Was this translation helpful? Give feedback.
-
Hey @jennyckaplan, We will release a Python package at some point, but not in the short term. In the meantime, building your own should be relatively straightforward. Our node package simply calls one of our REST API to generate a token. My python is a bit rusty and I've never used Flask but the code should look something like that (untested): import requests
from flask import Flask
from flask import request
app = Flask(__name__)
@app.route("/auth", methods = ['POST'])
def auth():
content = request.get_json(silent=True)
url = "https://liveblocks.io/api/authorize"
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + YOUR_SECRET_KEY,
}
data = {
"room": content.room,
"userId": "your-user-id", # Optional
"userData": { # Optional
"firstName": "Testy",
"lastName": "McTester"
},
}
response = requests.post(url, headers=headers, json=data)
return response.json(); I hope it helps! :) If it does not work, please let me know and I'll set up a Flask project on my machine to test it properly. |
Beta Was this translation helpful? Give feedback.
-
Thank you so much for the quick reply @GuillaumeSalles! Super impressed. I'm still not seeing my connection data reflected when using the Thanks again for all the help! UPDATE (resolved): I completely forgot to replace my public key on my client with Example for anyone else who gets stuck on this:
This client is then passed into the |
Beta Was this translation helpful? Give feedback.
-
Hey @jennyckaplan! Sorry for not being able to answer sooner... I'm glad you could figure it out! Thanks a lot for the detailed solution! I'm sure it will help other potential users :) I would only add one thing (it might not be relevant to you but just in case other users are seeing this): If you send user information to your Diagrams to make it clearer. From what I understand, your current setup looks like this: It might be okay if you validate the user information against the JWT or for other reasons that I'm not aware of. In any case, we care about the security of our users so I wanted to take the time to make it as clear as possible. Let me know if you have any other questions. |
Beta Was this translation helpful? Give feedback.
-
If you need to build an authentication endpoint but you're not using node.js, please let us know here.
Beta Was this translation helpful? Give feedback.
All reactions