Comments (6)
Yes! I ended up doing it this way:
@csrf_exempt
def get_private_token(request):
if not request.is_ajax() or not request.method == "POST":
raise Http404
data = json.loads(request.body)
client = data.get('client')
channels = data.get('channels')
token_list = []
for channel in channels:
channel_data = {
"channel": channel,
"token": generate_private_token(client, channel)
}
token_list.append(channel_data)
response_data = {
"channels": token_list
}
return JsonResponse(response_data)
def generate_private_token(client, channel):
token = jwt.encode({"client": client, "channel": channel}, secret, algorithm="HS256").decode()
return token
Thank you so much for your help!
from pycent.
@KakarN thanks, fixed!
from pycent.
@KakarN hello! you are looking at docs for Centrifugo v1. Actual doc is https://centrifugal.github.io/centrifugo/, see chapter about authentication (https://centrifugal.github.io/centrifugo/server/authentication/) which describes how to generate connection token for Centrifugo v2 using any JWT library.
from pycent.
Aha! Thank you!
from pycent.
See example on how to generate subscription token in Tornado example, also centrifuge-js docs about format expected.
from pycent.
@FZambia Hi! I just wanted to point out how I was reading the old version's documentation. On the High-level library API section, the URL link to check out the available Server API methods in the readme points to the old version documentation, and not the new version.
from pycent.
Related Issues (17)
- Python 3.3 Error HOT 2
- Publish by user
- Documentation HOT 4
- Introduce insecure skip verify option HOT 1
- How would I go about reading the API constantly? HOT 12
- Latest version does not work with v1 HOT 2
- Fix getting history HOT 2
- Missing Parameters HOT 2
- publish data with datetime or Decimal HOT 7
- Centrifugo on Production Server HOT 6
- is this client still receiving updates? HOT 8
- 404 on message publish HOT 2
- Get offset instead of publications for offset field in history response HOT 2
- Request for cent Package Availability in Anaconda
- Poll the server for number of clients HOT 12
- Use X-API-Sign header to set sign and POST commands in request body
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycent.