Git Product home page Git Product logo

Comments (6)

KakarN avatar KakarN commented on June 23, 2024 1

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.

FZambia avatar FZambia commented on June 23, 2024 1

@KakarN thanks, fixed!

from pycent.

FZambia avatar FZambia commented on June 23, 2024

@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.

KakarN avatar KakarN commented on June 23, 2024

Aha! Thank you!

from pycent.

FZambia avatar FZambia commented on June 23, 2024

See example on how to generate subscription token in Tornado example, also centrifuge-js docs about format expected.

from pycent.

KakarN avatar KakarN commented on June 23, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.