robertmrk / aiosfstream

Salesforce Streaming API client for asyncio
MIT License
47 stars 30 forks source link

[FEAT] Add support for JWT Authentication #20

Open emregunel opened 2 years ago

emregunel commented 2 years ago

JWT Authentication is a common scenario for Server to server applications.

It will be nice to have this supported built-in, otherwise developers will need to do it in their application.

Below should be possible after this implementation:

from aiosfstream.auth import JWTAuthenticator
from aiosfstream import Client

authenticator = JWTAuthenticator(consumer_key=",
                                 username="",
                                 private_key="")

async def stream_events():
    async with Client(authenticator) as client:

        await client.subscribe("/topic/1")

        async for message in client:
            topic = message["channel"]
            data = message["data"]
            print(f"{topic}: {data}")