In my implementation of the django getstream.io client, I have a backend code snippet that generates a read-only token and includes it in the response along with my jwt token upon successful login. This code snippet resides at the end of my settings.py file, where I have defined the STREAM_API_SECRET and STREAM_API_KEY keys which match the settings on my getstream.io dashboard.
from stream_django.client import stream_client
def jwt_response_payload_handler(token, user=None, request=None):
user_feed_1 = stream_client.feed('user', str(user.id))
readonly_token = user_feed_1.get_readonly_token()
return {
'token': token,
'stream': str(readonly_token)
}
When attempting to set up a real-time stream on the frontend using the obtained token from the login response, I encountered a "Not authenticated error" upon connection. Despite confirming that the token passed matches the generated one on the backend, the issue persists.
function setupStream (token, id) {
var client = stream.connect(STREAM_API_KEY, null, STREAM_APP_ID)
var user1 = client.feed('user', id, token)
function callback (data) {
console.log(data)
}
function failCallback (data) {
alert('something went wrong, check the console logs')
console.log(data)
}
user1.subscribe(callback).then(() => {}, failCallback)
}
Despite following the documentation, the functionality remains unresolved. As per the documentation guide:
An attempt to fetch data through the console resulted in an error response:
user1.get({ limit: 5, offset: 0 })
.then(callback)
.catch(failCallback)
The error response body was as follows:
{
"code": null,
"detail": "url signature missing or invalid",
"duration": "7ms",
"exception": "AuthenticationFailed",
"status_code": 403
}
EDIT:
After modifying the method from get_readonly_token() to .token, and creating a read/write token instead, the client-side code started functioning correctly. It raises the question if readonly tokens are not supported?